#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 */
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ header;
struct TYPE_6__ {
  int /*<<< orphan*/ e_type;
  int /*<<< orphan*/ e_ident;
};
typedef int /*<<< orphan*/ FILE;
typedef TYPE_1__ Elf64_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ parse_e_ident(int /*<<< orphan*/);
int /*<<< orphan*/ parse_header_meta(TYPE_1__);
int /*<<< orphan*/ parse_machine(int /*<<< orphan*/);
int /*<<< orphan*/ parse_program_headers(int /*<<< orphan*/ *, TYPE_1__);
int /*<<< orphan*/ parse_section_headers(int /*<<< orphan*/ *, TYPE_1__);
int /*<<< orphan*/ parse_type(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void analyze_64(FILE *fp) {
  fseek(fp, 0, SEEK_SET);
  Elf64_Ehdr header;
  fread(&header, sizeof(header), 1, fp);
  printf("File is a 64 bit executable");
  parse_e_ident(header.e_ident);
  parse_type(header.e_type);
  parse_machine(header.e_type);
  parse_header_meta(header);
  parse_section_headers(fp, header);
  parse_program_headers(fp, header);
}


x86 assembly (clang, -O0):
<analyze_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0x10(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1060 <fread@plt>
lea    0xe32(%rip),%rdi
call   1080 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <parse_e_ident@plt>
mov    -0x10(%rbp),%edi
call   1050 <parse_type@plt>
mov    -0x10(%rbp),%edi
call   10a0 <parse_machine@plt>
mov    -0x10(%rbp),%rdi
call   1030 <parse_header_meta@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <parse_section_headers@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <parse_program_headers@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<analyze_64>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
lea    0xe3e(%rip),%rdi
call   1080 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <parse_e_ident@plt>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1050 <parse_type@plt>
mov    %ebp,%edi
call   10a0 <parse_machine@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   1030 <parse_header_meta@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <parse_section_headers@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <parse_program_headers@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i32 }
@SEEK_SET = global i32 0
@.str = [28 x i8] c"File is a 64 bit executable\00"
define void @analyze_64(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.TYPE_6__
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* @SEEK_SET
%6 = call i32 @fseek(i32* %4, i32 0, i32 %5)
%7 = load i32*, i32** %2
%8 = call i32 @fread(%struct.TYPE_6__* %3, i32 8, i32 1, i32* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 @parse_e_ident(i32 %11)
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @parse_type(i32 %14)
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @parse_machine(i32 %17)
%19 = bitcast %struct.TYPE_6__* %3 to i64*
%20 = load i64, i64* %19
%21 = call i32 @parse_header_meta(i64 %20)
%22 = load i32*, i32** %2
%23 = bitcast %struct.TYPE_6__* %3 to i64*
%24 = load i64, i64* %23
%25 = call i32 @parse_section_headers(i32* %22, i64 %24)
%26 = load i32*, i32** %2
%27 = bitcast %struct.TYPE_6__* %3 to i64*
%28 = load i64, i64* %27
%29 = call i32 @parse_program_headers(i32* %26, i64 %28)
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i32 }
@SEEK_SET = global i32 0
@.str = [28 x i8] c"File is a 64 bit executable\00"
define void @analyze_64(i32* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.TYPE_6__*
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %0, i32 0, i32 %4)
%6 = bitcast i64* %2 to i8*
%7 = call i32 @fread(%struct.TYPE_6__* %3, i32 8, i32 1, i32* %0)
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = tail call i32 @parse_e_ident(i32 %10)
%12 = bitcast i64* %2 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 @parse_type(i32 %13)
%15 = tail call i32 @parse_machine(i32 %13)
%16 = load i64, i64* %2
%17 = tail call i32 @parse_header_meta(i64 %16)
%18 = tail call i32 @parse_section_headers(i32* %0, i64 %16)
%19 = tail call i32 @parse_program_headers(i32* %0, i64 %16)
ret void
}