#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 unsigned long long uint64_t;
struct stat {
  scalar_t__ st_size;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long long);
int sscanf(char *, char *, unsigned long long *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr;
  struct stat sb;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n", argv[0]);
    return EXIT_FAILURE;
  }
  if (stat(argv[1], &sb) == -1) {
    perror("stat");
    return EXIT_FAILURE;
  }
  errno = 0;
  if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) {
    if (errno != 0)
      perror("sscanf");
    else
      fprintf(stderr, "No matching characters\n");
    return EXIT_FAILURE;
  }
  vmlinux_size = (uint64_t)sb.st_size;
  vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;
  vmlinuz_load_addr += (16 - vmlinux_size % 16);
  printf("0x%llx\n", vmlinuz_load_addr);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x4f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x147>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x86>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x147>
mov    0x2dfb(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3c(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     124f <main+0xff>
mov    0x2dcc(%rip),%rax
cmpq   $0x0,(%rax)
je     1227 <main+0xd7>
lea    0xe17(%rip),%rdi
call   1070 <perror@plt>
jmp    123e <main+0xee>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x147>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
and    $0xf,%rcx
mov    $0x10,%eax
sub    %rcx,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11c9 <main+0x79>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1213 <main+0xc3>
mov    0x2e5b(%rip),%r14
movq   $0x0,(%r14)
mov    0x10(%rbx),%rdi
lea    0xea0(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11e5 <main+0x95>
mov    0x8(%rsp),%rsi
mov    %esi,%eax
and    $0xf,%eax
add    0x10(%rsp),%rsi
sub    %rax,%rsi
add    $0x10,%rsi
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e01(%rip),%rax
jmp    1209 <main+0xb9>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe24(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1202 <main+0xb2>
cmpq   $0x0,(%r14)
jne    121c <main+0xcc>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe10(%rip),%rdi
jmp    1223 <main+0xd3>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
jmp    1202 <main+0xb2>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [42 x i8] c"Usage: %s <pathname> <vmlinux_load_addr>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"stat\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"%llx\00"
@.str.3 = [7 x i8] c"sscanf\00"
@.str.4 = [24 x i8] c"No matching characters\0A\00"
@.str.5 = [8 x i8] c"0x%llx\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %58
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @stat(i8* %22, %struct.stat* %9)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %58
28: ; preds = %19
store i64 0, i64* @errno
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %7)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load i64, i64* @errno
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %42
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %39, %37
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %58
44: ; preds = %28
%45 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%46 = load i64, i64* %45
store i64 %46, i64* %6
%47 = load i64, i64* %7
%48 = load i64, i64* %6
%49 = add i64 %47, %48
store i64 %49, i64* %8
%50 = load i64, i64* %6
%51 = urem i64 %50, 16
%52 = sub i64 16, %51
%53 = load i64, i64* %8
%54 = add i64 %53, %52
store i64 %54, i64* %8
%55 = load i64, i64* %8
%56 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 %55)
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %3
br label %58
58: ; preds = %44, %42, %25, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [42 x i8] c"Usage: %s <pathname> <vmlinux_load_addr>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"stat\00"
@errno = global i64 0
@.str.2 = [5 x i8] c"%llx\00"
@.str.3 = [7 x i8] c"sscanf\00"
@.str.4 = [24 x i8] c"No matching characters\0A\00"
@.str.5 = [8 x i8] c"0x%llx\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca %struct.stat
%5 = bitcast i64* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %41
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @stat(i8* %14, %struct.stat* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %41
19: ; preds = %12
store i64 0, i64* @errno
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%23 = icmp eq i32 %22, 1
br i1 %23, label %32, label %24
24: ; preds = %19
%25 = load i64, i64* @errno
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %41
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %41
32: ; preds = %19
%33 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%34 = load i64, i64* %33
%35 = load i64, i64* %3
%36 = and i64 %34, 15
%37 = add i64 %34, 16
%38 = add i64 %37, %35
%39 = sub i64 %38, %36
%40 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %27, %29, %32, %17, %8
%42 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_SUCCESS, %32 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_FAILURE, %27 ]
%43 = load i32, i32* %42
ret i32 %43
}