#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;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  struct stat st;
  off_t size;
  if (argc != 2) {
    printf("E: Need a filename as an argument.\n");
    return EXIT_FAILURE;
  }
  if (stat(argv[1], &st) == -1) {
    perror("E: Can not stat input file");
    exit(EXIT_FAILURE);
  }
  size = st.st_size;
  setlocale(LC_ALL, "");
  printf("\nFile size: %'zi\n", size);
  return EXIT_SUCCESS;
}


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     118f <main+0x3f>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c3 <main+0x73>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <setlocale@plt>
mov    -0x1c(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-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    11af <main+0x4f>
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11ca <main+0x6a>
mov    0x8(%rsp),%ebx
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe7e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e2b(%rip),%rax
jmp    11c2 <main+0x62>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [36 x i8] c"E: Need a filename as an argument.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"E: Can not stat input file\00"
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"\0AFile size: %'zi\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 %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %3
br label %31
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @stat(i8* %16, %struct.stat* %6)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %7
%26 = load i32, i32* @LC_ALL
%27 = call i32 @setlocale(i32 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @EXIT_SUCCESS
store i32 %30, i32* %3
br label %31
31: ; preds = %23, %10
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"E: Can not stat input file\00"
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"\0AFile size: %'zi\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [35 x i8] c"E: Need a filename as an argument.\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 ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %23
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 %17
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @LC_ALL
%21 = tail call i32 @setlocale(i32 %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %23
23: ; preds = %17, %6
%24 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_SUCCESS, %17 ]
%25 = load i32, i32* %24
ret i32 %25
}