#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_1__;

/* Type definitions */
typedef int /*<<< orphan*/ elf_hdr;
struct TYPE_4__ {
  int e_phentsize;
  int /*<<< orphan*/ e_phoff;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ Elf64_Phdr;
typedef TYPE_1__ Elf64_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ check_seek(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ readn(int, TYPE_1__ *, int);
Elf64_Ehdr get_header(int fd) {
  check_seek(fd, 0, "lseek(hdr)");
  Elf64_Ehdr elf_hdr = {0};
  readn(fd, &elf_hdr, sizeof(elf_hdr));
  if (!elf_hdr.e_phoff) {
    err(1, "no phoff");
  }
  if (elf_hdr.e_phentsize != sizeof(Elf64_Phdr)) {
    err(1, "phsz is off");
  }
  return elf_hdr;
}


x86 assembly (clang, -O0):
<get_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
lea    0xea9(%rip),%rdx
call   1050 <check_seek@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1040 <readn@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1198 <get_header+0x58>
mov    $0x1,%edi
lea    0xe78(%rip),%rsi
call   1060 <err@plt>
movslq -0x10(%rbp),%rax
cmp    $0x4,%rax
je     11b7 <get_header+0x77>
mov    $0x1,%edi
lea    0xe62(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%edx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xec2(%rip),%rdx
xor    %esi,%esi
call   1040 <check_seek@plt>
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1030 <readn@plt>
cmpl   $0x0,0x4(%rsp)
je     1190 <get_header+0x60>
cmpl   $0x4,(%rsp)
je     1182 <get_header+0x52>
lea    0xe9c(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%edx
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe74(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
cmpl   $0x4,(%rsp)
jne    1171 <get_header+0x41>
jmp    1182 <get_header+0x52>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32 }
@.str = [11 x i8] c"lseek(hdr)\00"
@.str.1 = [9 x i8] c"no phoff\00"
@.str.2 = [12 x i8] c"phsz is off\00"
define { i64, i32 } @get_header(i32 %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca i32
%4 = alloca { i64, i32 }
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @check_seek(i32 %5, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = bitcast %struct.TYPE_4__* %2 to i8*
%8 = load i32, i32* %3
%9 = call i32 @readn(i32 %8, %struct.TYPE_4__* %2, i32 12)
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i32 0, i32 1
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = icmp ne i64 %18, 4
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = bitcast { i64, i32 }* %4 to i8*
%24 = bitcast %struct.TYPE_4__* %2 to i8*
%25 = load { i64, i32 }, { i64, i32 }* %4
ret { i64, i32 } %25
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32 }
@.str = [11 x i8] c"lseek(hdr)\00"
@.str.1 = [9 x i8] c"no phoff\00"
@.str.2 = [12 x i8] c"phsz is off\00"
define { i64, i32 } @get_header(i32 %0) {
%2 = alloca %struct.TYPE_4__
%3 = tail call i32 @check_seek(i32 %0, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = bitcast %struct.TYPE_4__* %2 to i8*
%5 = call i32 @readn(i32 %0, %struct.TYPE_4__* %2, i32 12)
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 4
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = bitcast %struct.TYPE_4__* %2 to i64*
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 2
%21 = load i32, i32* %20
%22 = insertvalue { i64, i32 } poison, i64 %19, 0
%23 = insertvalue { i64, i32 } %22, i32 %21, 1
ret { i64, i32 } %23
}