#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 */

/* Variables and functions */
int mount(char *, char *, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pivot_root(char *, char *);
int /*<<< orphan*/ printf(char *);
int bootcf() {
  int res;
  printf("mounting CF...\n");
  res = mount("/dev/hdc1", "/mnt/root", "ext3", 0, 0);
  if (res) {
    perror("Error mounting /dev/hdc1 on /mnt/root");
    res = mount("/dev/hdc", "/mnt/root", "ext3", 0, 0);
    if (res) {
      perror("Error mounting /dev/hdc on /mnt/root");
      return res;
    }
  }
  printf("pivot_root\n");
  res = pivot_root("/mnt/root", "/mnt/root/boot");
  if (res < 0) {
    perror("pivot_root");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bootcf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    0xed9(%rip),%rsi
lea    0xeb1(%rip),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <mount@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d6 <bootcf+0x96>
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
lea    0xeb1(%rip),%rdi
lea    0xea0(%rip),%rsi
lea    0xe78(%rip),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <mount@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d1 <bootcf+0x91>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <bootcf+0xe1>
jmp    11d6 <bootcf+0x96>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    0xe52(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <pivot_root@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    121a <bootcf+0xda>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <bootcf+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootcf>:
push   %rbp
push   %rbx
push   %rax
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaa(%rip),%rdi
lea    0xece(%rip),%rsi
lea    0xea6(%rip),%rdx
xor    %ebp,%ebp
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <mount@plt>
test   %eax,%eax
jne    11a3 <bootcf+0x63>
lea    0xf06(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1060 <pivot_root@plt>
test   %eax,%eax
js     11dd <bootcf+0x9d>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe65(%rip),%rdi
call   1050 <perror@plt>
lea    0xe7f(%rip),%rdi
lea    0xe6e(%rip),%rsi
lea    0xe46(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <mount@plt>
test   %eax,%eax
je     1174 <bootcf+0x34>
lea    0xe65(%rip),%rbx
mov    %eax,%ebp
jmp    11e2 <bootcf+0xa2>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <perror@plt>
jmp    119a <bootcf+0x5a>

LLVM IR (-O0):
@.str = [16 x i8] c"mounting CF...\0A\00"
@.str.1 = [10 x i8] c"/dev/hdc1\00"
@.str.2 = [10 x i8] c"/mnt/root\00"
@.str.3 = [5 x i8] c"ext3\00"
@.str.4 = [38 x i8] c"Error mounting /dev/hdc1 on /mnt/root\00"
@.str.5 = [9 x i8] c"/dev/hdc\00"
@.str.6 = [37 x i8] c"Error mounting /dev/hdc on /mnt/root\00"
@.str.7 = [12 x i8] c"pivot_root\0A\00"
@.str.8 = [15 x i8] c"/mnt/root/boot\00"
@.str.9 = [11 x i8] c"pivot_root\00"
define i32 @bootcf() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @mount(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%14 = load i32, i32* %2
store i32 %14, i32* %1
br label %24
15: ; preds = %7
br label %16
16: ; preds = %15, %0
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%18 = call i32 @pivot_root(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %1
br label %24
23: ; preds = %16
store i32 0, i32* %1
br label %24
24: ; preds = %23, %21, %12
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"/dev/hdc1\00"
@.str.2 = [10 x i8] c"/mnt/root\00"
@.str.3 = [5 x i8] c"ext3\00"
@.str.4 = [38 x i8] c"Error mounting /dev/hdc1 on /mnt/root\00"
@.str.5 = [9 x i8] c"/dev/hdc\00"
@.str.6 = [37 x i8] c"Error mounting /dev/hdc on /mnt/root\00"
@.str.8 = [15 x i8] c"/mnt/root/boot\00"
@str = [15 x i8] c"mounting CF...\00"
@str.10 = [11 x i8] c"pivot_root\00"
define i32 @bootcf() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call i32 @mount(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4, %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0))
%10 = tail call i32 @pivot_root(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8, %4
%13 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), %4 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0), %8 ]
%14 = phi i32 [ %6, %4 ], [ 1, %8 ]
%15 = tail call i32 @perror(i8* %13)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ 0, %8 ], [ %14, %12 ]
ret i32 %17
}