#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 /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  struct stat filestat;
  if (argc != 2) {
    printf("enter filename\n");
    return 1;
  }
  if (stat(argv[1], &filestat) == -1) {
    perror(argv[1]);
    return 1;
  }
  printf("file size is %lld\n", filestat.st_size);
  return 0;
}


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)
je     116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    119d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <main+0x85>
mov    -0x18(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1176 <main+0x36>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     118f <main+0x4f>
mov    0x8(%rsp),%esi
lea    0xe95(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1187 <main+0x47>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rbx),%rdi
call   1060 <perror@plt>
jmp    1182 <main+0x42>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [19 x i8] c"file size is %lld\0A\00"
@str = [15 x i8] c"enter filename\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 %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %20
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @stat(i8* %10, %struct.stat* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 @perror(i8* %14)
br label %20
16: ; preds = %8
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %13, %6
%21 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 0, %16 ]
ret i32 %21
}