#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 scalar_t__ dev_t;

/* Variables and functions */
scalar_t__ __makedev(int, int);
int atoi(char const *);
char *bdevname(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
char *get_arg(int, char **, char *);
int /*<<< orphan*/ getintfile(char *, long *);
scalar_t__ initrd_load(int, char **, scalar_t__);
int /*<<< orphan*/ md_run(int, char **);
int mount_root(int, char **, scalar_t__, char const *);
scalar_t__ name_to_dev_t(char const *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ramdisk_load(int, char **, scalar_t__);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int do_mounts(int argc, char *argv[]) {
  const char *root_dev_name = get_arg(argc, argv, "root=");
  const char *root_delay = get_arg(argc, argv, "rootdelay=");
  const char *load_ramdisk = get_arg(argc, argv, "load_ramdisk=");
  dev_t root_dev = 0;
  printf("kinit: do_mounts\n");
  if (root_delay) {
    int delay = atoi(root_delay);
    fprintf(stderr, "Waiting %d s before mounting root device...\n", delay);
    sleep(delay);
  }
  md_run(argc, argv);
  if (root_dev_name) {
    root_dev = name_to_dev_t(root_dev_name);
  } else if (get_arg(argc, argv, "nfsroot=") ||
             get_arg(argc, argv, "nfsaddrs=")) {
    root_dev = __makedev(0, 255);
  } else {
    long rootdev;
    getintfile("/proc/sys/kernel/real-root-dev", &rootdev);
    root_dev = (dev_t)rootdev;
  }
  printf("kinit: root_dev = %s\n", bdevname(root_dev));
  if (initrd_load(argc, argv, root_dev)) {
    printf("initrd loaded\n");
    return 0;
  }
  if (load_ramdisk && atoi(load_ramdisk)) {
    if (ramdisk_load(argc, argv, root_dev))
      root_dev = __makedev(1, 0);
  }
  return mount_root(argc, argv, root_dev, root_dev_name);
}


x86 assembly (clang, -O0):
<do_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6e(%rip),%rdx
call   1070 <get_arg@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfc(%rip),%rdx
call   1070 <get_arg@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdf0(%rip),%rdx
call   1070 <get_arg@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     1271 <do_mounts+0xa1>
mov    -0x20(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xdc7(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   10f0 <sleep@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <md_run@plt>
cmpq   $0x0,-0x18(%rbp)
je     129a <do_mounts+0xca>
mov    -0x18(%rbp),%rdi
call   1080 <name_to_dev_t@plt>
mov    %rax,-0x30(%rbp)
jmp    1306 <do_mounts+0x136>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdb0(%rip),%rdx
call   1070 <get_arg@plt>
cmp    $0x0,%rax
jne    12d4 <do_mounts+0x104>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd9c(%rip),%rdx
call   1070 <get_arg@plt>
cmp    $0x0,%rax
je     12e9 <do_mounts+0x119>
xor    %edi,%edi
mov    $0xff,%esi
call   10e0 <__makedev@plt>
mov    %rax,-0x30(%rbp)
jmp    1301 <do_mounts+0x131>
lea    0xd7b(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <getintfile@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1306 <do_mounts+0x136>
mov    -0x30(%rbp),%rdi
call   1050 <bdevname@plt>
mov    %rax,%rsi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <initrd_load@plt>
cmp    $0x0,%rax
je     1354 <do_mounts+0x184>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b7 <do_mounts+0x1e7>
cmpq   $0x0,-0x28(%rbp)
je     13a0 <do_mounts+0x1d0>
mov    -0x28(%rbp),%rdi
call   10b0 <atoi@plt>
cmp    $0x0,%eax
je     13a0 <do_mounts+0x1d0>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10c0 <ramdisk_load@plt>
cmp    $0x0,%rax
je     139b <do_mounts+0x1cb>
mov    $0x1,%edi
xor    %esi,%esi
call   10e0 <__makedev@plt>
mov    %rax,-0x30(%rbp)
jmp    13a0 <do_mounts+0x1d0>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   10a0 <mount_root@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_mounts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r13d
lea    0xe51(%rip),%rdx
call   1080 <get_arg@plt>
mov    %rax,%r14
lea    0xdf9(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1080 <get_arg@plt>
mov    %rax,%rbx
lea    0xdef(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1080 <get_arg@plt>
mov    %rax,%r15
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
test   %rbx,%rbx
je     1263 <do_mounts+0x83>
mov    %rbx,%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebx
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    %ebx,%edx
call   10a0 <fprintf@plt>
mov    %ebx,%edi
call   1100 <sleep@plt>
mov    %r13d,%edi
mov    %r12,%rsi
call   10e0 <md_run@plt>
test   %r14,%r14
je     127d <do_mounts+0x9d>
mov    %r14,%rdi
call   1090 <name_to_dev_t@plt>
jmp    12bb <do_mounts+0xdb>
lea    0xdc2(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1080 <get_arg@plt>
test   %rax,%rax
jne    12af <do_mounts+0xcf>
lea    0xdb4(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1080 <get_arg@plt>
test   %rax,%rax
je     1351 <do_mounts+0x171>
xor    %edi,%edi
mov    $0xff,%esi
call   10f0 <__makedev@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1060 <bdevname@plt>
lea    0xdab(%rip),%rdi
xor    %ebp,%ebp
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <initrd_load@plt>
test   %rax,%rax
je     12fa <do_mounts+0x11a>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
jmp    1340 <do_mounts+0x160>
test   %r15,%r15
je     132d <do_mounts+0x14d>
mov    %r15,%rdi
call   10c0 <atoi@plt>
test   %eax,%eax
je     132d <do_mounts+0x14d>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10d0 <ramdisk_load@plt>
test   %rax,%rax
je     132d <do_mounts+0x14d>
mov    $0x1,%edi
xor    %esi,%esi
call   10f0 <__makedev@plt>
mov    %rax,%rbx
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10b0 <mount_root@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd01(%rip),%rdi
mov    %rsp,%rsi
call   1050 <getintfile@plt>
mov    (%rsp),%rbx
jmp    12be <do_mounts+0xde>

LLVM IR (-O0):
@.str = [6 x i8] c"root=\00"
@.str.1 = [11 x i8] c"rootdelay=\00"
@.str.2 = [14 x i8] c"load_ramdisk=\00"
@.str.3 = [18 x i8] c"kinit: do_mounts\0A\00"
@stderr = global i32 0
@.str.4 = [45 x i8] c"Waiting %d s before mounting root device...\0A\00"
@.str.5 = [9 x i8] c"nfsroot=\00"
@.str.6 = [10 x i8] c"nfsaddrs=\00"
@.str.7 = [31 x i8] c"/proc/sys/kernel/real-root-dev\00"
@.str.8 = [22 x i8] c"kinit: root_dev = %s\0A\00"
@.str.9 = [15 x i8] c"initrd loaded\0A\00"
define i32 @do_mounts(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i8* @get_arg(i32 %12, i8** %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i8* @get_arg(i32 %15, i8** %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %7
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i8* @get_arg(i32 %18, i8** %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %8
store i64 0, i64* %9
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %32
24: ; preds = %2
%25 = load i8*, i8** %7
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %10
%27 = load i32, i32* @stderr
%28 = load i32, i32* %10
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %10
%31 = call i32 @sleep(i32 %30)
br label %32
32: ; preds = %24, %2
%33 = load i32, i32* %4
%34 = load i8**, i8*** %5
%35 = call i32 @md_run(i32 %33, i8** %34)
%36 = load i8*, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i8*, i8** %6
%40 = call i64 @name_to_dev_t(i8* %39)
store i64 %40, i64* %9
br label %57
41: ; preds = %32
%42 = load i32, i32* %4
%43 = load i8**, i8*** %5
%44 = call i8* @get_arg(i32 %42, i8** %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp ne i8* %44, null
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = load i32, i32* %4
%48 = load i8**, i8*** %5
%49 = call i8* @get_arg(i32 %47, i8** %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %46, %41
%52 = call i64 @__makedev(i32 0, i32 255)
store i64 %52, i64* %9
br label %56
53: ; preds = %46
%54 = call i32 @getintfile(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64* %11)
%55 = load i64, i64* %11
store i64 %55, i64* %9
br label %56
56: ; preds = %53, %51
br label %57
57: ; preds = %56, %38
%58 = load i64, i64* %9
%59 = call i8* @bdevname(i64 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %59)
%61 = load i32, i32* %4
%62 = load i8**, i8*** %5
%63 = load i64, i64* %9
%64 = call i64 @initrd_load(i32 %61, i8** %62, i64 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %57
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %90
68: ; preds = %57
%69 = load i8*, i8** %8
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %84
71: ; preds = %68
%72 = load i8*, i8** %8
%73 = call i32 @atoi(i8* %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %84
75: ; preds = %71
%76 = load i32, i32* %4
%77 = load i8**, i8*** %5
%78 = load i64, i64* %9
%79 = call i64 @ramdisk_load(i32 %76, i8** %77, i64 %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %75
%82 = call i64 @__makedev(i32 1, i32 0)
store i64 %82, i64* %9
br label %83
83: ; preds = %81, %75
br label %84
84: ; preds = %83, %71, %68
%85 = load i32, i32* %4
%86 = load i8**, i8*** %5
%87 = load i64, i64* %9
%88 = load i8*, i8** %6
%89 = call i32 @mount_root(i32 %85, i8** %86, i64 %87, i8* %88)
store i32 %89, i32* %3
br label %90
90: ; preds = %84, %66
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str = [6 x i8] c"root=\00"
@.str.1 = [11 x i8] c"rootdelay=\00"
@.str.2 = [14 x i8] c"load_ramdisk=\00"
@stderr = global i32 0
@.str.4 = [45 x i8] c"Waiting %d s before mounting root device...\0A\00"
@.str.5 = [9 x i8] c"nfsroot=\00"
@.str.6 = [10 x i8] c"nfsaddrs=\00"
@.str.7 = [31 x i8] c"/proc/sys/kernel/real-root-dev\00"
@.str.8 = [22 x i8] c"kinit: root_dev = %s\0A\00"
@str = [17 x i8] c"kinit: do_mounts\00"
@str.10 = [14 x i8] c"initrd loaded\00"
define i32 @do_mounts(i32 %0, i8** %1) {
%3 = alloca i64
%4 = tail call i8* @get_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @get_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @get_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%8 = icmp eq i8* %5, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = tail call i32 @atoi(i8* %5)
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%13 = tail call i32 @sleep(i32 %10)
br label %14
14: ; preds = %9, %2
%15 = tail call i32 @md_run(i32 %0, i8** %1)
%16 = icmp eq i8* %4, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i64 @name_to_dev_t(i8* %4)
br label %31
19: ; preds = %14
%20 = tail call i8* @get_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i8* @get_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %22, %19
%26 = tail call i64 @__makedev(i32 0, i32 255)
br label %31
27: ; preds = %22
%28 = bitcast i64* %3 to i8*
%29 = call i32 @getintfile(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64* %3)
%30 = load i64, i64* %3
br label %31
31: ; preds = %25, %27, %17
%32 = phi i64 [ %18, %17 ], [ %26, %25 ], [ %30, %27 ]
%33 = call i8* @bdevname(i64 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %33)
%35 = call i64 @initrd_load(i32 %0, i8** %1, i64 %32)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %31
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %52
39: ; preds = %31
%40 = icmp eq i8* %6, null
br i1 %40, label %49, label %41
41: ; preds = %39
%42 = call i32 @atoi(i8* %6)
%43 = icmp eq i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = call i64 @ramdisk_load(i32 %0, i8** %1, i64 %32)
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i64 @__makedev(i32 1, i32 0)
br label %49
49: ; preds = %44, %47, %41, %39
%50 = phi i64 [ %48, %47 ], [ %32, %44 ], [ %32, %41 ], [ %32, %39 ]
%51 = call i32 @mount_root(i32 %0, i8** %1, i64 %50, i8* %4)
br label %52
52: ; preds = %49, %37
%53 = phi i32 [ 0, %37 ], [ %51, %49 ]
ret i32 %53
}