#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*/ printf(char *, char *, ...);
int stat(char *, struct stat *);
int main(int argc, char **argv) {
  struct stat buf;
  int r = stat(argv[1], &buf);
  if (r == 0) {
    unsigned long sz = (buf.st_size >> 20);
    printf("size of %s = %ldMB\n", argv[1], sz);
  } else {
    printf("get size of %s failed\n", argv[1]);
  }
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    117f <main+0x5f>
mov    -0x18(%rbp),%eax
sar    $0x14,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1195 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     114e <main+0x2e>
mov    0x8(%rbx),%rsi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    116a <main+0x4a>
mov    0x8(%rsp),%eax
sar    $0x14,%eax
movslq %eax,%rdx
mov    0x8(%rbx),%rsi
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"size of %s = %ldMB\0A\00"
@.str.1 = [23 x i8] c"get size of %s failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @stat(i8* %11, %struct.stat* %6)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%17 = load i32, i32* %16
%18 = ashr i32 %17, 20
%19 = sext i32 %18 to i64
store i64 %19, i64* %8
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i64, i64* %8
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %22, i64 %23)
br label %30
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %15
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"size of %s = %ldMB\0A\00"
@.str.1 = [23 x i8] c"get size of %s failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @stat(i8* %6, %struct.stat* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = ashr i32 %11, 20
%13 = sext i32 %12 to i64
%14 = load i8*, i8** %5
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14, i64 %13)
br label %19
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %9
ret i32 0
}