#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int __u32;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int send_status(int, int *);
int /*<<< orphan*/ stderr;
int write_extcsd_value(int, int, int);
int set_partitioning_setting_completed(int dry_run, const char *const device,
                                       int fd) {
  int ret;
  if (dry_run) {
    fprintf(stderr, "NOT setting PARTITION_SETTING_COMPLETED\n");
    fprintf(stderr, "These changes will not take effect neither "
                    "now nor after a power cycle\n");
    return 1;
  }
  fprintf(stderr, "setting OTP PARTITION_SETTING_COMPLETED!\n");
  ret = write_extcsd_value(fd, 155, 0x1);
  if (ret) {
    fprintf(stderr,
            "Could not write 0x1 to "
            "EXT_CSD[%d] in %s\n",
            155, device);
    return 1;
  }
  __u32 response;
  ret = send_status(fd, &response);
  if (ret) {
    fprintf(stderr,
            "Could not get response to SEND_STATUS "
            "from %s\n",
            device);
    return 1;
  }
  if (response & (1 << 7)) {
    fprintf(stderr,
            "Setting OTP PARTITION_SETTING_COMPLETED "
            "failed on %s\n",
            device);
    return 1;
  }
  fprintf(stderr,
          "Setting OTP PARTITION_SETTING_COMPLETED on "
          "%s SUCCESS\n",
          device);
  fprintf(stderr, "Device power cycle needed for settings to "
                  "take effect.\n"
                  "Confirm that PARTITION_SETTING_COMPLETED bit is set "
                  "using 'extcsd read' after power cycle\n");
  return 0;
}


x86 assembly (clang, -O0):
<set_partitioning_setting_completed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1186 <set_partitioning_setting_completed+0x56>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <set_partitioning_setting_completed+0x169>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xedb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    $0x9b,%esi
mov    $0x1,%edx
call   1050 <write_extcsd_value@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e8 <set_partitioning_setting_completed+0xb8>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xecb(%rip),%rsi
mov    $0x9b,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <set_partitioning_setting_completed+0x169>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <send_status@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1228 <set_partitioning_setting_completed+0xf8>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <set_partitioning_setting_completed+0x169>
mov    -0x1c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1260 <set_partitioning_setting_completed+0x130>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <set_partitioning_setting_completed+0x169>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xeb6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xed6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_partitioning_setting_completed>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
mov    0x2ea0(%rip),%r15
mov    (%r15),%edi
test   %eax,%eax
je     116d <set_partitioning_setting_completed+0x3d>
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edi
lea    0xeca(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
jmp    11b3 <set_partitioning_setting_completed+0x83>
mov    %edx,%ebx
mov    %rsi,%r14
lea    0xef8(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
mov    $0x9b,%esi
mov    $0x1,%edx
call   1050 <write_extcsd_value@plt>
test   %eax,%eax
je     11c0 <set_partitioning_setting_completed+0x90>
mov    (%r15),%edi
lea    0xef7(%rip),%rsi
mov    $0x9b,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
call   1030 <send_status@plt>
test   %eax,%eax
je     11dc <set_partitioning_setting_completed+0xac>
mov    (%r15),%edi
lea    0xeeb(%rip),%rsi
jmp    1213 <set_partitioning_setting_completed+0xe3>
testb  $0x80,0x4(%rsp)
mov    (%r15),%edi
jne    120c <set_partitioning_setting_completed+0xdc>
lea    0xf3d(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%edi
lea    0xf5e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b3 <set_partitioning_setting_completed+0x83>
lea    0xee1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1166 <set_partitioning_setting_completed+0x36>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"NOT setting PARTITION_SETTING_COMPLETED\0A\00"
@.str.1 = [72 x i8] c"These changes will not take effect neither now nor after a power cycle\0A\00"
@.str.2 = [42 x i8] c"setting OTP PARTITION_SETTING_COMPLETED!\0A\00"
@.str.3 = [42 x i8] c"Could not write 0x1 to EXT_CSD[%d] in %s\0A\00"
@.str.4 = [47 x i8] c"Could not get response to SEND_STATUS from %s\0A\00"
@.str.5 = [54 x i8] c"Setting OTP PARTITION_SETTING_COMPLETED failed on %s\0A\00"
@.str.6 = [55 x i8] c"Setting OTP PARTITION_SETTING_COMPLETED on %s SUCCESS\0A\00"
@.str.7 = [146 x i8] c"Device power cycle needed for settings to take effect.\0AConfirm that PARTITION_SETTING_COMPLETED bit is set using 'extcsd read' after power cycle\0A\00"
define i32 @set_partitioning_setting_completed(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %51
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = call i32 @write_extcsd_value(i32 %20, i32 155, i32 1)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 155, i8* %26)
store i32 1, i32* %4
br label %51
28: ; preds = %17
%29 = load i32, i32* %7
%30 = call i32 @send_status(i32 %29, i32* %9)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %6
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %35)
store i32 1, i32* %4
br label %51
37: ; preds = %28
%38 = load i32, i32* %9
%39 = and i32 %38, 128
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %6
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %43)
store i32 1, i32* %4
br label %51
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %6
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %51
51: ; preds = %45, %41, %33, %24, %12
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"NOT setting PARTITION_SETTING_COMPLETED\0A\00"
@.str.1 = [72 x i8] c"These changes will not take effect neither now nor after a power cycle\0A\00"
@.str.2 = [42 x i8] c"setting OTP PARTITION_SETTING_COMPLETED!\0A\00"
@.str.3 = [42 x i8] c"Could not write 0x1 to EXT_CSD[%d] in %s\0A\00"
@.str.4 = [47 x i8] c"Could not get response to SEND_STATUS from %s\0A\00"
@.str.5 = [54 x i8] c"Setting OTP PARTITION_SETTING_COMPLETED failed on %s\0A\00"
@.str.6 = [55 x i8] c"Setting OTP PARTITION_SETTING_COMPLETED on %s SUCCESS\0A\00"
@.str.7 = [146 x i8] c"Device power cycle needed for settings to take effect.\0AConfirm that PARTITION_SETTING_COMPLETED bit is set using 'extcsd read' after power cycle\0A\00"
define i32 @set_partitioning_setting_completed(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = icmp eq i32 %0, 0
%6 = load i32, i32* @stderr
br i1 %5, label %11, label %7
7: ; preds = %3
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %38
11: ; preds = %3
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @write_extcsd_value(i32 %2, i32 155, i32 1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 155, i8* %1)
br label %38
18: ; preds = %11
%19 = bitcast i32* %4 to i8*
%20 = call i32 @send_status(i32 %2, i32* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %1)
br label %36
25: ; preds = %18
%26 = load i32, i32* %4
%27 = and i32 %26, 128
%28 = icmp eq i32 %27, 0
%29 = load i32, i32* @stderr
br i1 %28, label %32, label %30
30: ; preds = %25
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %1)
br label %36
32: ; preds = %25
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.7, i64 0, i64 0))
br label %36
36: ; preds = %32, %30, %22
%37 = phi i32 [ 1, %22 ], [ 1, %30 ], [ 0, %32 ]
br label %38
38: ; preds = %36, %15, %7
%39 = phi i32 [ 1, %7 ], [ 1, %15 ], [ %37, %36 ]
ret i32 %39
}