#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int e_entry;
  int e_type;
  int e_machine;
  int e_version;
  int e_phoff;
  int e_phnum;
  int e_phentsize;
};
struct TYPE_3__ {
  int p_type;
};
typedef int /*<<< orphan*/ FILE;
typedef int Elf32_Word;
typedef TYPE_1__ Elf32_Phdr;
typedef int Elf32_Off;
typedef int Elf32_Half;
typedef TYPE_2__ Elf32_Ehdr;
typedef int Elf32_Addr;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *fp = NULL;
  Elf32_Ehdr *header = NULL;
  char *data = NULL;
  Elf32_Phdr *p = NULL;
  if (argc != 2) {
    fprintf(stderr, "syntax %s file_name\n", argv[0]);
    exit(-1);
  }
  if (!(fp = fopen(argv[1], "r"))) {
    fprintf(stderr, "error opening file %s\n", argv[1]);
    exit(-2);
  }
  data = (char *)malloc(sizeof(Elf32_Ehdr));
  fread(data, sizeof(Elf32_Ehdr), 1, fp);
  header = (Elf32_Ehdr *)data;
  printf("e_entry %X\n", header->e_entry);
  printf("testing offset of e_type\n");
  printf("%X\n", header->e_type);
  printf("%X\n", *(Elf32_Half *)(data + 0x10));
  printf("testing offset of e_machine\n");
  printf("%X\n", header->e_machine);
  printf("%X\n", *(Elf32_Half *)(data + 0x12));
  printf("testing offset of e_version\n");
  printf("%X\n", header->e_version);
  printf("%X\n", *(Elf32_Word *)(data + 0x14));
  printf("testing offset of e_entry\n");
  printf("%X\n", header->e_entry);
  printf("%X\n", *(Elf32_Addr *)(data + 0x18));
  printf("testing offset of e_phoff\n");
  printf("%X\n", header->e_phoff);
  printf("%X\n", *(Elf32_Off *)(data + 0x1C));
  printf("testing offset of e_phnum\n");
  printf("%X\n", header->e_phnum);
  printf("%X\n", *(Elf32_Half *)(data + 0x2C));
  printf("testing offset of e_phentsize\n");
  printf("%X\n", header->e_phentsize);
  printf("%X\n", *(Elf32_Half *)(data + 0x2A));
  printf("testing pht location %X\n",
         (((header->e_phnum - 1) * header->e_phentsize) + header->e_phoff +
          0x14000));
  p = (Elf32_Phdr *)data + 0x54;
  printf("testing Elf32_Phdr->p_type %X\n", p->p_type);
DONE:
  fclose(fp);
  fp = NULL;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11cf <main+0x5f>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1218 <main+0xa8>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>
mov    $0x1c,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1c,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x12(%rax),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x1c(%rax),%esi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x2c(%rax),%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x2a(%rax),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rax
imul   0x18(%rax),%esi
mov    -0x20(%rbp),%rax
add    0x10(%rax),%esi
add    $0x14000,%esi
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x150,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1337 <main+0x1b7>
mov    0x8(%rbx),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1359 <main+0x1d9>
mov    %rax,%r14
mov    $0x1c,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    (%rbx),%esi
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rbx),%esi
lea    0xe79(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x12(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2a(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%eax
mov    0x14(%rbx),%ecx
add    $0xffffffff,%ecx
imul   0x18(%rbx),%ecx
lea    (%rax,%rcx,1),%esi
add    $0x14000,%esi
lea    0xd2e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x150(%rbx),%esi
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcb6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xcaa(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.TYPE_3__ = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"syntax %s file_name\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"error opening file %s\0A\00"
@.str.3 = [12 x i8] c"e_entry %X\0A\00"
@.str.4 = [26 x i8] c"testing offset of e_type\0A\00"
@.str.5 = [4 x i8] c"%X\0A\00"
@.str.6 = [29 x i8] c"testing offset of e_machine\0A\00"
@.str.7 = [29 x i8] c"testing offset of e_version\0A\00"
@.str.8 = [27 x i8] c"testing offset of e_entry\0A\00"
@.str.9 = [27 x i8] c"testing offset of e_phoff\0A\00"
@.str.10 = [27 x i8] c"testing offset of e_phnum\0A\00"
@.str.11 = [31 x i8] c"testing offset of e_phentsize\0A\00"
@.str.12 = [25 x i8] c"testing pht location %X\0A\00"
@.str.13 = [31 x i8] c"testing Elf32_Phdr->p_type %X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca %struct.TYPE_4__*
%7 = alloca i8*
%8 = alloca %struct.TYPE_3__*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32* null, i32** %5
store %struct.TYPE_4__* null, %struct.TYPE_4__** %6
store i8* null, i8** %7
store %struct.TYPE_3__* null, %struct.TYPE_3__** %8
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %5
%23 = icmp ne i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 -2)
unreachable
31: ; preds = %18
%32 = call i64 @malloc(i32 28)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = load i32*, i32** %5
%36 = call i32 @fread(i8* %34, i32 28, i32 1, i32* %35)
%37 = load i8*, i8** %7
%38 = bitcast i8* %37 to %struct.TYPE_4__*
store %struct.TYPE_4__* %38, %struct.TYPE_4__** %6
%39 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%44 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 16
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 2
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i64 18
%60 = bitcast i8* %59 to i32*
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%64 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%65 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %64, i32 0, i32 3
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load i8*, i8** %7
%69 = getelementptr inbounds i8, i8* %68, i64 20
%70 = bitcast i8* %69 to i32*
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%74 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%75 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %76)
%78 = load i8*, i8** %7
%79 = getelementptr inbounds i8, i8* %78, i64 24
%80 = bitcast i8* %79 to i32*
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%84 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%85 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %84, i32 0, i32 4
%86 = load i32, i32* %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %86)
%88 = load i8*, i8** %7
%89 = getelementptr inbounds i8, i8* %88, i64 28
%90 = bitcast i8* %89 to i32*
%91 = load i32, i32* %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %91)
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%94 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%95 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %94, i32 0, i32 5
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %96)
%98 = load i8*, i8** %7
%99 = getelementptr inbounds i8, i8* %98, i64 44
%100 = bitcast i8* %99 to i32*
%101 = load i32, i32* %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %101)
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%104 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%105 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %104, i32 0, i32 6
%106 = load i32, i32* %105
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %106)
%108 = load i8*, i8** %7
%109 = getelementptr inbounds i8, i8* %108, i64 42
%110 = bitcast i8* %109 to i32*
%111 = load i32, i32* %110
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %111)
%113 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%114 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %113, i32 0, i32 5
%115 = load i32, i32* %114
%116 = sub nsw i32 %115, 1
%117 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%118 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %117, i32 0, i32 6
%119 = load i32, i32* %118
%120 = mul nsw i32 %116, %119
%121 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%122 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %121, i32 0, i32 4
%123 = load i32, i32* %122
%124 = add nsw i32 %120, %123
%125 = add nsw i32 %124, 81920
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %125)
%127 = load i8*, i8** %7
%128 = bitcast i8* %127 to %struct.TYPE_3__*
%129 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %128, i64 84
store %struct.TYPE_3__* %129, %struct.TYPE_3__** %8
%130 = load %struct.TYPE_3__*, %struct.TYPE_3__** %8
%131 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %130, i32 0, i32 0
%132 = load i32, i32* %131
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %132)
br label %134
134: ; preds = %31
%135 = load i32*, i32** %5
%136 = call i32 @fclose(i32* %135)
store i32* null, i32** %5
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.TYPE_3__ = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"syntax %s file_name\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"error opening file %s\0A\00"
@.str.3 = [12 x i8] c"e_entry %X\0A\00"
@.str.5 = [4 x i8] c"%X\0A\00"
@.str.12 = [25 x i8] c"testing pht location %X\0A\00"
@.str.13 = [31 x i8] c"testing Elf32_Phdr->p_type %X\0A\00"
@str = [25 x i8] c"testing offset of e_type\00"
@str.14 = [28 x i8] c"testing offset of e_machine\00"
@str.15 = [28 x i8] c"testing offset of e_version\00"
@str.16 = [26 x i8] c"testing offset of e_entry\00"
@str.17 = [26 x i8] c"testing offset of e_phoff\00"
@str.18 = [26 x i8] c"testing offset of e_phnum\00"
@str.19 = [30 x i8] c"testing offset of e_phentsize\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 -2)
unreachable
19: ; preds = %9
%20 = tail call i64 @malloc(i32 28)
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 @fread(i8* %21, i32 28, i32 1, i32* %12)
%23 = inttoptr i64 %20 to %struct.TYPE_4__*
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 0
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 1
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i8, i8* %21, i64 16
%32 = bitcast i8* %31 to i32*
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.14, i64 0, i64 0))
%36 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 2
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i8, i8* %21, i64 18
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.15, i64 0, i64 0))
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 3
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %21, i64 20
%48 = bitcast i8* %47 to i32*
%49 = load i32, i32* %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.16, i64 0, i64 0))
%52 = load i32, i32* %24
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds i8, i8* %21, i64 24
%55 = bitcast i8* %54 to i32*
%56 = load i32, i32* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.17, i64 0, i64 0))
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 4
%60 = load i32, i32* %59
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds i8, i8* %21, i64 28
%63 = bitcast i8* %62 to i32*
%64 = load i32, i32* %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %64)
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.18, i64 0, i64 0))
%67 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 5
%68 = load i32, i32* %67
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds i8, i8* %21, i64 44
%71 = bitcast i8* %70 to i32*
%72 = load i32, i32* %71
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %72)
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.19, i64 0, i64 0))
%75 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 6
%76 = load i32, i32* %75
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %76)
%78 = getelementptr inbounds i8, i8* %21, i64 42
%79 = bitcast i8* %78 to i32*
%80 = load i32, i32* %79
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %80)
%82 = load i32, i32* %67
%83 = add nsw i32 %82, -1
%84 = load i32, i32* %75
%85 = mul nsw i32 %83, %84
%86 = load i32, i32* %59
%87 = add i32 %86, 81920
%88 = add i32 %87, %85
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %88)
%90 = inttoptr i64 %20 to %struct.TYPE_3__*
%91 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %90, i64 84, i32 0
%92 = load i32, i32* %91
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %92)
%94 = tail call i32 @fclose(i32* %12)
ret i32 0
}