#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 print_shdr(char const *, int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int main(int argc, char *argv[]) {
  struct stat st;
  const char *fname = "/proc/self/exe";
  if (argc > 1)
    fname = argv[1];
  if (stat(fname, &st) != 0) {
    perror("stat");
    return 1;
  }
  return print_shdr(fname, st.st_size);
}


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)
lea    0xeb3(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1167 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1196 <main+0x66>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <main+0x75>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <print_shdr@plt>
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
jl     1140 <main+0x10>
mov    0x8(%rsi),%rbx
jmp    1147 <main+0x17>
lea    0xeb9(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
jne    116b <main+0x3b>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_shdr@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    1165 <main+0x35>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [5 x i8] c"stat\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = call i64 @stat(i8* %10, %struct.stat* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %19
15: ; preds = %9
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @print_shdr(i8* %10, i32 %17)
br label %19
19: ; preds = %15, %13
%20 = phi i32 [ 1, %13 ], [ %18, %15 ]
ret i32 %20
}