#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;
};
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;
  pwrite(h, &ehdr, sizeof(Elf32_Ehdr), 0);
  close(h);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11d7 <main+0x97>
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    11d7 <main+0x97>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1060 <pread@plt>
mov    -0x20(%rbp),%rax
movl   $0x1,0x3c(%rax)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%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    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32* }
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 %29
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 %29
19: ; preds = %11
%20 = load i32, i32* %6
%21 = call i32 @pread(i32 %20, %struct.TYPE_4__* %7, i32 8, 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 = load i32, i32* %6
%26 = call i32 @pwrite(i32 %25, %struct.TYPE_4__* %7, i32 8, i32 0)
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %19, %18, %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32* }
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_4__
%4 = icmp slt i32 %0, 2
br i1 %4, label %20, 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 %18, label %11
11: ; preds = %5
%12 = call i32 @pread(i32 %8, %struct.TYPE_4__* %3, i32 8, 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 = call i32 @pwrite(i32 %8, %struct.TYPE_4__* %3, i32 8, i32 0)
%17 = tail call i32 @close(i32 %8)
br label %18
18: ; preds = %5, %11
%19 = phi i32 [ 0, %11 ], [ 2, %5 ]
br label %20
20: ; preds = %2, %18
%21 = phi i32 [ %19, %18 ], [ 2, %2 ]
ret i32 %21
}