#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 */
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ snprintf(char *, int /*<<< orphan*/, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int boot_size(char *root, char *kernel, char *initrd, char *ginitrd) {
  struct stat buf;
  int ret;
  char path[PATH_MAX + 1];
  snprintf(path, PATH_MAX, "%s/%s", root, kernel);
  if (stat(path, &buf))
    return (0);
  ret = buf.st_size / 1024;
  snprintf(path, PATH_MAX, "%s/%s", root, initrd);
  if (stat(path, &buf))
    return (0);
  ret += buf.st_size / 1024;
  snprintf(path, PATH_MAX, "%s/%s", root, ginitrd);
  if (stat(path, &buf))
    return (0);
  ret += buf.st_size / 1024;
  return (ret);
}


x86 assembly (clang, -O0):
<boot_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe81(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11ae <boot_size+0x8e>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1281 <boot_size+0x161>
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe28(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1207 <boot_size+0xe7>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1281 <boot_size+0x161>
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xdcc(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1263 <boot_size+0x143>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1281 <boot_size+0x161>
mov    -0x30(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<boot_size>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r13
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r8
mov    %rdi,%r12
mov    %rsp,-0x40(%rbp)
mov    0x2ea7(%rip),%r14
mov    (%r14),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%r14),%esi
lea    0xe96(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    11bb <boot_size+0x9b>
mov    %r13,-0x50(%rbp)
mov    -0x30(%rbp),%r13d
mov    (%r14),%esi
lea    0xe65(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    -0x38(%rbp),%r8
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
je     11d4 <boot_size+0xb4>
mov    -0x40(%rbp),%r13
mov    %r13,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    %rax,-0x48(%rbp)
mov    (%r14),%esi
lea    0xe17(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    -0x50(%rbp),%r8
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
mov    -0x40(%rbp),%r13
jne    11bf <boot_size+0x9f>
mov    -0x38(%rbp),%rcx
lea    0x3ff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0xa,%eax
mov    -0x48(%rbp),%rdx
lea    0x3ff(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
sar    $0xa,%ecx
add    %eax,%ecx
mov    -0x30(%rbp),%eax
lea    0x3ff(%rax),%r15d
test   %eax,%eax
cmovns %eax,%r15d
sar    $0xa,%r15d
add    %ecx,%r15d
jmp    11bf <boot_size+0x9f>

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define i32 @boot_size(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%15 = load i32, i32* @PATH_MAX
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i32, i32* @PATH_MAX
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 @snprintf(i8* %19, i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = call i64 @stat(i8* %19, %struct.stat* %10)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %4
store i32 0, i32* %5
store i32 1, i32* %14
br label %58
27: ; preds = %4
%28 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sdiv i32 %29, 1024
store i32 %30, i32* %11
%31 = load i32, i32* @PATH_MAX
%32 = load i8*, i8** %6
%33 = load i8*, i8** %8
%34 = call i32 @snprintf(i8* %19, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %33)
%35 = call i64 @stat(i8* %19, %struct.stat* %10)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %27
store i32 0, i32* %5
store i32 1, i32* %14
br label %58
38: ; preds = %27
%39 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sdiv i32 %40, 1024
%42 = load i32, i32* %11
%43 = add nsw i32 %42, %41
store i32 %43, i32* %11
%44 = load i32, i32* @PATH_MAX
%45 = load i8*, i8** %6
%46 = load i8*, i8** %9
%47 = call i32 @snprintf(i8* %19, i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %45, i8* %46)
%48 = call i64 @stat(i8* %19, %struct.stat* %10)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %38
store i32 0, i32* %5
store i32 1, i32* %14
br label %58
51: ; preds = %38
%52 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sdiv i32 %53, 1024
%55 = load i32, i32* %11
%56 = add nsw i32 %55, %54
store i32 %56, i32* %11
%57 = load i32, i32* %11
store i32 %57, i32* %5
store i32 1, i32* %14
br label %58
58: ; preds = %51, %50, %37, %26
%59 = load i8*, i8** %12
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define i32 @boot_size(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.stat
%6 = bitcast %struct.stat* %5 to i8*
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = load i32, i32* @PATH_MAX
%13 = call i32 @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%14 = call i64 @stat(i8* %11, %struct.stat* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %4
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @PATH_MAX
%20 = call i32 @snprintf(i8* %11, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2)
%21 = call i64 @stat(i8* %11, %struct.stat* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %16
%24 = load i32, i32* %17
%25 = load i32, i32* @PATH_MAX
%26 = call i32 @snprintf(i8* %11, i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %3)
%27 = call i64 @stat(i8* %11, %struct.stat* %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = sdiv i32 %18, 1024
%31 = sdiv i32 %24, 1024
%32 = add nsw i32 %31, %30
%33 = load i32, i32* %17
%34 = sdiv i32 %33, 1024
%35 = add nsw i32 %32, %34
br label %36
36: ; preds = %23, %16, %4, %29
%37 = phi i32 [ %35, %29 ], [ 0, %4 ], [ 0, %16 ], [ 0, %23 ]
ret i32 %37
}