#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EI_CLASS;
#define ELFCLASS32 129
#define ELFCLASS64 128
unsigned char ELFMAG0;
unsigned char ELFMAG1;
unsigned char ELFMAG2;
unsigned char ELFMAG3;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *input;
  char *pgm_name;
  char *file_name;
  size_t count;
  unsigned char buffer[EI_CLASS + 1];
  pgm_name = argv[0];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file>\n", pgm_name);
    exit(1);
  }
  file_name = argv[1];
  input = fopen(file_name, "r");
  if (input == NULL) {
    fprintf(stderr, "%s: can't open file '%s'\n", pgm_name, file_name);
    exit(1);
  }
  count = fread(buffer, 1, sizeof(buffer), input);
  if (count != sizeof(buffer)) {
    fprintf(stderr, "%s: can't read ELF header from file '%s'\n", pgm_name,
            file_name);
    exit(1);
  }
  if ((buffer[0] != ELFMAG0) || (buffer[1] != ELFMAG1) ||
      (buffer[2] != ELFMAG2) || (buffer[3] != ELFMAG3)) {
    fprintf(stderr, "%s: file '%s' is not ELF file.\n", pgm_name, file_name);
    exit(1);
  }
  switch (buffer[EI_CLASS]) {
  case ELFCLASS32:
    printf("32\n");
    break;
  case ELFCLASS64:
    printf("64\n");
    break;
  default:
    fprintf(stderr, "%s: file '%s' has unknown elf class (%d)\n", pgm_name,
            file_name, buffer[EI_CLASS]);
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d3 <main+0x83>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1227 <main+0xd7>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,-0x30(%rbp)
cmp    %rax,-0x30(%rbp)
je     127d <main+0x12d>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
mov    0x2d4d(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12e4 <main+0x194>
mov    -0x48(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    0x2d4b(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12e4 <main+0x194>
mov    -0x48(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    0x2cf9(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12e4 <main+0x194>
mov    -0x48(%rbp),%rax
movzbl 0x3(%rax),%eax
mov    0x2d1f(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     130d <main+0x1bd>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x48(%rbp),%rax
mov    0x2cb0(%rip),%rcx
movslq (%rcx),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x54(%rbp)
sub    $0x80,%eax
je     1356 <main+0x206>
jmp    1332 <main+0x1e2>
mov    -0x54(%rbp),%eax
sub    $0x81,%eax
jne    1367 <main+0x217>
jmp    1345 <main+0x1f5>
lea    0xd2c(%rip),%rdi
call   1040 <printf@plt>
jmp    13a3 <main+0x253>
lea    0xd1f(%rip),%rdi
call   1040 <printf@plt>
jmp    13a3 <main+0x253>
mov    -0x48(%rbp),%rax
mov    0x2c4e(%rip),%rcx
mov    (%rcx),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    0x2c45(%rip),%rsi
movslq (%rsi),%rsi
movzbl (%rax,%rsi,1),%r8d
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e63(%rip),%r13
mov    0x0(%r13),%ebx
add    $0x1,%ebx
mov    %rsp,%r12
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    (%rsi),%r15
cmp    $0x2,%edi
jne    11b2 <main+0x62>
mov    0x8(%rsi),%r14
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11d6 <main+0x86>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
jmp    126f <main+0x11f>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    %rbx,%rax
jne    124d <main+0xfd>
mov    (%r12),%al
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%al
jne    125f <main+0x10f>
mov    0x1(%r12),%al
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%al
jne    125f <main+0x10f>
mov    0x2(%r12),%al
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%al
jne    125f <main+0x10f>
mov    0x3(%r12),%al
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%al
jne    125f <main+0x10f>
movslq 0x0(%r13),%rax
movzbl (%r12,%rax,1),%r8d
cmp    $0x81,%r8d
je     1286 <main+0x136>
cmp    $0x80,%r8b
jne    1299 <main+0x149>
lea    0xe57(%rip),%rdi
jmp    128d <main+0x13d>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
jmp    126f <main+0x11f>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EI_CLASS = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"%s: can't open file '%s'\0A\00"
@.str.3 = [42 x i8] c"%s: can't read ELF header from file '%s'\0A\00"
@ELFMAG0 = global i8 0
@ELFMAG1 = global i8 0
@ELFMAG2 = global i8 0
@ELFMAG3 = global i8 0
@.str.4 = [32 x i8] c"%s: file '%s' is not ELF file.\0A\00"
@.str.5 = [4 x i8] c"32\0A\00"
@.str.6 = [4 x i8] c"64\0A\00"
@.str.7 = [42 x i8] c"%s: file '%s' has unknown elf class (%d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @EI_CLASS
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %10
%16 = alloca i8, i64 %14
store i64 %14, i64* %11
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %7
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %41
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %7
%38 = load i8*, i8** %8
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %27
%42 = trunc i64 %14 to i32
%43 = load i32*, i32** %6
%44 = call i64 @fread(i8* %16, i32 1, i32 %42, i32* %43)
store i64 %44, i64* %9
%45 = load i64, i64* %9
%46 = icmp ne i64 %45, %14
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %7
%50 = load i8*, i8** %8
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %41
%54 = getelementptr inbounds i8, i8* %16, i64 0
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = load i8, i8* @ELFMAG0
%58 = zext i8 %57 to i32
%59 = icmp ne i32 %56, %58
br i1 %59, label %81, label %60
60: ; preds = %53
%61 = getelementptr inbounds i8, i8* %16, i64 1
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = load i8, i8* @ELFMAG1
%65 = zext i8 %64 to i32
%66 = icmp ne i32 %63, %65
br i1 %66, label %81, label %67
67: ; preds = %60
%68 = getelementptr inbounds i8, i8* %16, i64 2
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = load i8, i8* @ELFMAG2
%72 = zext i8 %71 to i32
%73 = icmp ne i32 %70, %72
br i1 %73, label %81, label %74
74: ; preds = %67
%75 = getelementptr inbounds i8, i8* %16, i64 3
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = load i8, i8* @ELFMAG3
%79 = zext i8 %78 to i32
%80 = icmp ne i32 %77, %79
br i1 %80, label %81, label %87
81: ; preds = %74, %67, %60, %53
%82 = load i32, i32* @stderr
%83 = load i8*, i8** %7
%84 = load i8*, i8** %8
%85 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %83, i8* %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %74
%88 = load i32, i32* @EI_CLASS
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %16, i64 %89
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
switch i32 %92, label %97 [
i32 129, label %93
i32 128, label %95
]
93: ; preds = %87
%94 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %108
95: ; preds = %87
%96 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %108
97: ; preds = %87
%98 = load i32, i32* @stderr
%99 = load i8*, i8** %7
%100 = load i8*, i8** %8
%101 = load i32, i32* @EI_CLASS
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %16, i64 %102
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %99, i8* %100, i32 %105)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %95, %93
%109 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@EI_CLASS = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"%s: can't open file '%s'\0A\00"
@.str.3 = [42 x i8] c"%s: can't read ELF header from file '%s'\0A\00"
@ELFMAG0 = global i8 0
@ELFMAG1 = global i8 0
@ELFMAG2 = global i8 0
@ELFMAG3 = global i8 0
@.str.4 = [32 x i8] c"%s: file '%s' is not ELF file.\0A\00"
@.str.7 = [42 x i8] c"%s: file '%s' has unknown elf class (%d)\0A\00"
@str = [3 x i8] c"64\00"
@str.8 = [3 x i8] c"32\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @EI_CLASS
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = load i8*, i8** %1
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %15)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = call i64 @fread(i8* %6, i32 1, i32 %4, i32* %16)
%24 = icmp eq i64 %23, %5
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %15)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = load i8, i8* %6
%31 = load i8, i8* @ELFMAG0
%32 = icmp eq i8 %30, %31
br i1 %32, label %33, label %48
33: ; preds = %29
%34 = getelementptr inbounds i8, i8* %6, i64 1
%35 = load i8, i8* %34
%36 = load i8, i8* @ELFMAG1
%37 = icmp eq i8 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %33
%39 = getelementptr inbounds i8, i8* %6, i64 2
%40 = load i8, i8* %39
%41 = load i8, i8* @ELFMAG2
%42 = icmp eq i8 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = getelementptr inbounds i8, i8* %6, i64 3
%45 = load i8, i8* %44
%46 = load i8, i8* @ELFMAG3
%47 = icmp eq i8 %45, %46
br i1 %47, label %52, label %48
48: ; preds = %43, %38, %33, %29
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %15)
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %43
%53 = load i32, i32* @EI_CLASS
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %6, i64 %54
%56 = load i8, i8* %55
switch i8 %56, label %58 [
i8 -127, label %63
i8 -128, label %57
]
57: ; preds = %52
br label %63
58: ; preds = %52
%59 = zext i8 %56 to i32
%60 = load i32, i32* @stderr
%61 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %7, i8* %15, i32 %59)
%62 = tail call i32 @exit(i32 1)
unreachable
63: ; preds = %52, %57
%64 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), %57 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0), %52 ]
%65 = tail call i32 @puts(i8* dereferenceable(1) %64)
%66 = tail call i32 @exit(i32 0)
unreachable
}