#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ e_type;
  scalar_t__ e_machine;
  scalar_t__ e_version;
  int /*<<< orphan*/ e_ident;
};
typedef TYPE_1__ Elf32_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ ELFMAG;
scalar_t__ EM_386;
scalar_t__ ET_EXEC;
scalar_t__ EV_CURRENT;
int /*<<< orphan*/ SELFMAG;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void do_elf_checks(Elf32_Ehdr *ehdr) {
  if (strncmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
    fprintf(stderr, "File not ELF");
    exit(1);
  }
  if (ehdr->e_type != ET_EXEC) {
    fprintf(stderr, "ELF type not ET_EXEC or ET_DYN");
    exit(1);
  }
  if (ehdr->e_machine != EM_386) {
    fprintf(stderr, "ELF machine type not EM_386");
    exit(1);
  }
  if (ehdr->e_version != EV_CURRENT) {
    fprintf(stderr, "ELF version not current");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<do_elf_checks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1183 <do_elf_checks+0x53>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     11b9 <do_elf_checks+0x89>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%rax
je     11f0 <do_elf_checks+0xc0>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
je     1227 <do_elf_checks+0xf7>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_elf_checks>:
push   %rbx
mov    %rdi,%rbx
mov    0x18(%rdi),%edi
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1184 <do_elf_checks+0x54>
mov    (%rbx),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <do_elf_checks+0x66>
mov    0x8(%rbx),%rax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
jne    11a8 <do_elf_checks+0x78>
mov    0x10(%rbx),%rax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <do_elf_checks+0x8a>
pop    %rbx
ret
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
jmp    11ca <do_elf_checks+0x9a>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
jmp    11ca <do_elf_checks+0x9a>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
jmp    11ca <do_elf_checks+0x9a>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64, i64, i32 }
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"File not ELF\00"
@ET_EXEC = global i64 0
@.str.1 = [31 x i8] c"ELF type not ET_EXEC or ET_DYN\00"
@EM_386 = global i64 0
@.str.2 = [28 x i8] c"ELF machine type not EM_386\00"
@EV_CURRENT = global i64 0
@.str.3 = [24 x i8] c"ELF version not current\00"
define void @do_elf_checks(%struct.TYPE_3__* %0) {
%2 = alloca %struct.TYPE_3__*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %2
%3 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 3
%5 = load i32, i32* %4
%6 = load i32, i32* @ELFMAG
%7 = load i32, i32* @SELFMAG
%8 = call i64 @strncmp(i32 %5, i32 %6, i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @ET_EXEC
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = load i64, i64* @EM_386
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 2
%37 = load i64, i64* %36
%38 = load i64, i64* @EV_CURRENT
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64, i64, i32 }
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"File not ELF\00"
@ET_EXEC = global i64 0
@.str.1 = [31 x i8] c"ELF type not ET_EXEC or ET_DYN\00"
@EM_386 = global i64 0
@.str.2 = [28 x i8] c"ELF machine type not EM_386\00"
@EV_CURRENT = global i64 0
@.str.3 = [24 x i8] c"ELF version not current\00"
define void @do_elf_checks(%struct.TYPE_3__* nocapture %0) {
%2 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 3
%3 = load i32, i32* %2
%4 = load i32, i32* @ELFMAG
%5 = load i32, i32* @SELFMAG
%6 = tail call i64 @strncmp(i32 %3, i32 %4, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @ET_EXEC
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%23 = load i64, i64* %22
%24 = load i64, i64* @EM_386
%25 = icmp eq i64 %23, %24
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%32 = load i64, i64* %31
%33 = load i64, i64* @EV_CURRENT
%34 = icmp eq i64 %32, %33
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %30
ret void
}