#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
void failed_ensure(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int snprintf(char *, int, char *, int);
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
void set_boot_partition(int part) {
  char buf[10];
  int len;
  len = snprintf(buf, sizeof(buf), "%d", part);
  int fd = open("/sys/module/bcm2708/parameters/reboot_part", O_WRONLY);
  if (fd >= 0) {
    ((write(fd, buf, len) == len) ? (void)(0)
                                  : failed_ensure("write reboot_part", 163));
    ;
  } else {
    printf("Couldn't open /sys/module/bcm2708/parameters/reboot_part : %s\n",
           strerror(errno));
  }
  close(fd);
}


x86 assembly (clang, -O0):
<set_boot_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xe(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0xa,%esi
lea    0xe72(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11eb <set_boot_partition+0x7b>
mov    -0x18(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
jne    11d5 <set_boot_partition+0x65>
jmp    11e6 <set_boot_partition+0x76>
lea    0xe52(%rip),%rdi
mov    $0xa3,%esi
call   1070 <failed_ensure@plt>
jmp    1208 <set_boot_partition+0x98>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_boot_partition>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ecx
lea    0xe81(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1050 <snprintf@plt>
mov    %eax,%ebp
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11d0 <set_boot_partition+0x60>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     11ed <set_boot_partition+0x7d>
lea    0xe6a(%rip),%rdi
mov    $0xa3,%esi
call   1070 <failed_ensure@plt>
jmp    11ed <set_boot_partition+0x7d>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [43 x i8] c"/sys/module/bcm2708/parameters/reboot_part\00"
@O_WRONLY = global i32 0
@.str.2 = [18 x i8] c"write reboot_part\00"
@.str.3 = [63 x i8] c"Couldn't open /sys/module/bcm2708/parameters/reboot_part : %s\0A\00"
@errno = global i32 0
define void @set_boot_partition(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @snprintf(i8* %6, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = load i32, i32* %5
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @write(i32 %14, i8* %15, i32 %16)
%18 = load i32, i32* %4
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
br label %22
21: ; preds = %13
br label %22
22: ; preds = %21, %20
br label %27
23: ; preds = %1
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %22
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [43 x i8] c"/sys/module/bcm2708/parameters/reboot_part\00"
@O_WRONLY = global i32 0
@.str.2 = [18 x i8] c"write reboot_part\00"
@.str.3 = [63 x i8] c"Couldn't open /sys/module/bcm2708/parameters/reboot_part : %s\0A\00"
@errno = global i32 0
define void @set_boot_partition(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @write(i32 %6, i8* %3, i32 %4)
%10 = icmp eq i32 %9, %4
br i1 %10, label %16, label %11
11: ; preds = %8
br label %16
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %11, %8, %12
%17 = call i32 @close(i32 %6)
ret void
}