#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 __u8;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read_extcsd(int, int *);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int write_extcsd_value(int, int, int);
int do_write_boot_en(int nargs, char **argv) {
  __u8 ext_csd[512];
  __u8 value = 0;
  int fd, ret;
  char *device;
  int boot_area, send_ack;
  {
    if (nargs != 4) {
      fprintf(stderr, "Usage: mmc bootpart enable <partition_number> "
                      "<send_ack> </path/to/mmcblkX>\n");
      exit(1);
    }
  };
  boot_area = strtol(argv[1], NULL, 10);
  send_ack = strtol(argv[2], NULL, 10);
  device = argv[3];
  fd = open(device, O_RDWR);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  ret = read_extcsd(fd, ext_csd);
  if (ret) {
    fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
    exit(1);
  }
  value = ext_csd[179];
  switch (boot_area) {
  case (0x1):
    value |= (1 << 3);
    value &= ~(3 << 4);
    break;
  case (0x2):
    value |= (1 << 4);
    value &= ~(1 << 3);
    value &= ~(1 << 5);
    break;
  case (0x7):
    value |= (boot_area << 3);
    break;
  default:
    fprintf(stderr, "Cannot enable the boot area\n");
    exit(1);
  }
  if (send_ack)
    value |= (0x40);
  else
    value &= ~(0x40);
  ret = write_extcsd_value(fd, 179, value);
  if (ret) {
    fprintf(stderr,
            "Could not write 0x%02x to "
            "EXT_CSD[%d] in %s\n",
            value, 179, device);
    exit(1);
  }
  return ret;
}


x86 assembly (clang, -O0):
<do_write_boot_en>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x814(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11b7 <do_write_boot_en+0x47>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x82c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x830(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x0,-0x818(%rbp)
jge    123c <do_write_boot_en+0xcc>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x818(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <read_extcsd@plt>
mov    %eax,-0x81c(%rbp)
cmpl   $0x0,-0x81c(%rbp)
je     1289 <do_write_boot_en+0x119>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x828(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x544(%rbp),%eax
mov    %eax,-0x814(%rbp)
mov    -0x82c(%rbp),%eax
mov    %eax,-0x834(%rbp)
sub    $0x1,%eax
je     12d7 <do_write_boot_en+0x167>
jmp    12af <do_write_boot_en+0x13f>
mov    -0x834(%rbp),%eax
sub    $0x2,%eax
je     12fa <do_write_boot_en+0x18a>
jmp    12c3 <do_write_boot_en+0x153>
mov    -0x834(%rbp),%eax
sub    $0x7,%eax
je     132c <do_write_boot_en+0x1bc>
jmp    1346 <do_write_boot_en+0x1d6>
mov    -0x814(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%eax
and    $0xffffffcf,%eax
mov    %eax,-0x814(%rbp)
jmp    1367 <do_write_boot_en+0x1f7>
mov    -0x814(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%eax
and    $0xfffffff7,%eax
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%eax
and    $0xffffffdf,%eax
mov    %eax,-0x814(%rbp)
jmp    1367 <do_write_boot_en+0x1f7>
mov    -0x82c(%rbp),%eax
shl    $0x3,%eax
or     -0x814(%rbp),%eax
mov    %eax,-0x814(%rbp)
jmp    1367 <do_write_boot_en+0x1f7>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x830(%rbp)
je     1388 <do_write_boot_en+0x218>
mov    -0x814(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x814(%rbp)
jmp    1397 <do_write_boot_en+0x227>
mov    -0x814(%rbp),%eax
and    $0xffffffbf,%eax
mov    %eax,-0x814(%rbp)
mov    -0x818(%rbp),%edi
mov    -0x814(%rbp),%edx
mov    $0xb3,%esi
call   1050 <write_extcsd_value@plt>
mov    %eax,-0x81c(%rbp)
cmpl   $0x0,-0x81c(%rbp)
je     13f3 <do_write_boot_en+0x283>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
mov    -0x828(%rbp),%r8
lea    0xcb2(%rip),%rsi
mov    $0xb3,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x81c(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_write_boot_en>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
cmp    $0x4,%edi
jne    123e <do_write_boot_en+0xce>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%r14
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1250 <do_write_boot_en+0xe0>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1060 <read_extcsd@plt>
test   %eax,%eax
jne    1266 <do_write_boot_en+0xf6>
mov    0x2cc(%rsp),%eax
cmp    $0x7,%ebx
je     1201 <do_write_boot_en+0x91>
cmp    $0x2,%ebx
je     1206 <do_write_boot_en+0x96>
cmp    $0x1,%ebx
jne    12b5 <do_write_boot_en+0x145>
and    $0xffffffc7,%eax
or     $0x8,%eax
jmp    120c <do_write_boot_en+0x9c>
or     $0x38,%eax
jmp    120c <do_write_boot_en+0x9c>
and    $0xffffffc7,%eax
or     $0x10,%eax
xor    %ebx,%ebx
test   %r15d,%r15d
setne  %bl
and    $0xffffffbf,%eax
shl    $0x6,%ebx
or     %eax,%ebx
mov    %ebp,%edi
mov    $0xb3,%esi
mov    %ebx,%edx
call   1050 <write_extcsd_value@plt>
test   %eax,%eax
jne    128a <do_write_boot_en+0x11a>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
jmp    12c5 <do_write_boot_en+0x155>
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    %ebx,%edx
mov    $0xb3,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [77 x i8] c"Usage: mmc bootpart enable <partition_number> <send_ack> </path/to/mmcblkX>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [32 x i8] c"Could not read EXT_CSD from %s\0A\00"
@.str.3 = [29 x i8] c"Cannot enable the boot area\0A\00"
@.str.4 = [45 x i8] c"Could not write 0x%02x to EXT_CSD[%d] in %s\0A\00"
define i32 @do_write_boot_en(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [512 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtol(i8* %21, i32* null, i32 10)
store i32 %22, i32* %10
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strtol(i8* %25, i32* null, i32 10)
store i32 %26, i32* %11
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %18
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %18
%39 = load i32, i32* %7
%40 = getelementptr inbounds [512 x i32], [512 x i32]* %5, i64 0, i64 0
%41 = call i32 @read_extcsd(i32 %39, i32* %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %9
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = getelementptr inbounds [512 x i32], [512 x i32]* %5, i64 0, i64 179
%51 = load i32, i32* %50
store i32 %51, i32* %6
%52 = load i32, i32* %10
switch i32 %52, label %70 [
i32 1, label %53
i32 2, label %58
i32 7, label %65
]
53: ; preds = %49
%54 = load i32, i32* %6
%55 = or i32 %54, 8
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = and i32 %56, -49
store i32 %57, i32* %6
br label %74
58: ; preds = %49
%59 = load i32, i32* %6
%60 = or i32 %59, 16
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = and i32 %61, -9
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = and i32 %63, -33
store i32 %64, i32* %6
br label %74
65: ; preds = %49
%66 = load i32, i32* %10
%67 = shl i32 %66, 3
%68 = load i32, i32* %6
%69 = or i32 %68, %67
store i32 %69, i32* %6
br label %74
70: ; preds = %49
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %65, %58, %53
%75 = load i32, i32* %11
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* %6
%79 = or i32 %78, 64
store i32 %79, i32* %6
br label %83
80: ; preds = %74
%81 = load i32, i32* %6
%82 = and i32 %81, -65
store i32 %82, i32* %6
br label %83
83: ; preds = %80, %77
%84 = load i32, i32* %7
%85 = load i32, i32* %6
%86 = call i32 @write_extcsd_value(i32 %84, i32 179, i32 %85)
store i32 %86, i32* %8
%87 = load i32, i32* %8
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %83
%90 = load i32, i32* @stderr
%91 = load i32, i32* %6
%92 = load i8*, i8** %9
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %91, i32 179, i8* %92)
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %83
%96 = load i32, i32* %8
ret i32 %96
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [77 x i8] c"Usage: mmc bootpart enable <partition_number> <send_ack> </path/to/mmcblkX>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [32 x i8] c"Could not read EXT_CSD from %s\0A\00"
@.str.3 = [29 x i8] c"Cannot enable the boot area\0A\00"
@.str.4 = [45 x i8] c"Could not write 0x%02x to EXT_CSD[%d] in %s\0A\00"
define i32 @do_write_boot_en(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i32]
%4 = bitcast [512 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strtol(i8* nocapture %12, i32* null, i32 10)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @strtol(i8* nocapture %15, i32* null, i32 10)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDWR
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %10
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %10
%26 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%27 = call i32 @read_extcsd(i32 %20, i32* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 179
%35 = load i32, i32* %34
switch i32 %13, label %44 [
i32 1, label %36
i32 2, label %39
i32 7, label %42
]
36: ; preds = %33
%37 = and i32 %35, -57
%38 = or i32 %37, 8
br label %48
39: ; preds = %33
%40 = and i32 %35, -57
%41 = or i32 %40, 16
br label %48
42: ; preds = %33
%43 = or i32 %35, 56
br label %48
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42, %39, %36
%49 = phi i32 [ %43, %42 ], [ %41, %39 ], [ %38, %36 ]
%50 = icmp eq i32 %16, 0
%51 = and i32 %49, -65
%52 = select i1 %50, i32 0, i32 64
%53 = or i32 %51, %52
%54 = call i32 @write_extcsd_value(i32 %20, i32 179, i32 %53)
%55 = icmp eq i32 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %48
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %53, i32 179, i8* %18)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %48
ret i32 0
}