#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 */
struct TYPE_4__ {
  int *e_ident;
  scalar_t__ e_shnum;
  scalar_t__ e_shoff;
};
typedef TYPE_1__ Elf32_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ pread(int, TYPE_1__ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ pwrite(int, TYPE_1__ *, int, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 2)
    return 2;
  int h = open(argv[1], 2);
  Elf32_Ehdr ehdr;
  if (h < 0)
    return 2;
  pread(h, &ehdr, sizeof(Elf32_Ehdr), 0);
  ehdr.e_ident[15] = 1;
  ehdr.e_shoff = 0;
  ehdr.e_shnum = 0;
  pwrite(h, &ehdr, sizeof(Elf32_Ehdr), 0);
  close(h);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x2,-0x4(%rbp)
jmp    11e7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2,%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1197 <main+0x57>
movl   $0x2,-0x4(%rbp)
jmp    11e7 <main+0xa7>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1060 <pread@plt>
mov    -0x30(%rbp),%rax
movl   $0x1,0x3c(%rax)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1040 <pwrite@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x2,%ebx
cmp    $0x2,%edi
jl     11af <main+0x6f>
mov    0x8(%rsi),%rdi
mov    $0x2,%ebx
mov    $0x2,%esi
call   1050 <open@plt>
test   %eax,%eax
js     11af <main+0x6f>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1060 <pread@plt>
mov    0x8(%rsp),%rax
movl   $0x1,0x3c(%rax)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x18,%edx
xor    %ecx,%ecx
call   1040 <pwrite@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32*, i64, i64 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.TYPE_4__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 2, i32* %3
br label %31
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @open(i8* %14, i32 2)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
store i32 2, i32* %3
br label %31
19: ; preds = %11
%20 = load i32, i32* %6
%21 = call i32 @pread(i32 %20, %struct.TYPE_4__* %7, i32 24, i32 0)
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i64 15
store i32 1, i32* %24
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 2
store i64 0, i64* %25
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
store i64 0, i64* %26
%27 = load i32, i32* %6
%28 = call i32 @pwrite(i32 %27, %struct.TYPE_4__* %7, i32 24, i32 0)
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
store i32 0, i32* %3
br label %31
31: ; preds = %19, %18, %10
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i64, i64 }
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_4__
%4 = icmp slt i32 %0, 2
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @open(i8* %7, i32 2)
%9 = bitcast %struct.TYPE_4__* %3 to i8*
%10 = icmp slt i32 %8, 0
br i1 %10, label %20, label %11
11: ; preds = %5
%12 = call i32 @pread(i32 %8, %struct.TYPE_4__* %3, i32 24, i32 0)
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 15
store i32 1, i32* %15
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
%17 = bitcast i64* %16 to i8*
%18 = call i32 @pwrite(i32 %8, %struct.TYPE_4__* %3, i32 24, i32 0)
%19 = tail call i32 @close(i32 %8)
br label %20
20: ; preds = %5, %11
%21 = phi i32 [ 0, %11 ], [ 2, %5 ]
br label %22
22: ; preds = %2, %20
%23 = phi i32 [ %21, %20 ], [ 2, %2 ]
ret i32 %23
}