#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 {
  scalar_t__ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct stat buf;
  if (argc == 2) {
    if (!stat(argv[1], &buf)) {
      unsigned long l = (unsigned long)buf.st_size;
      printf("%lu", l);
      return 0;
    } else
      return 1;
  } else {
    fprintf(stderr, "filesize: must give filename as single argument\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    119a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%eax
jne    118e <main+0x5e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <main+0x86>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <main+0x86>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    114f <main+0x1f>
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
je     116b <main+0x3b>
pop    %rcx
ret
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    (%rsp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [4 x i8] c"%lu\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"filesize: must give filename as single argument\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @stat(i8* %13, %struct.stat* %6)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%18 = load i64, i64* %17
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %19)
store i32 0, i32* %3
br label %25
21: ; preds = %10
store i32 1, i32* %3
br label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %25
25: ; preds = %22, %21, %16
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [4 x i8] c"%lu\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"filesize: must give filename as single argument\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @stat(i8* %8, %struct.stat* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %6, %15, %11
%19 = phi i32 [ 0, %11 ], [ 1, %15 ], [ 1, %6 ]
ret i32 %19
}