#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 */

/* Type definitions */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int write(int, char *, int);
int hack_frame(int f, char *buff) {
  ssize_t wrote_bytes;
  if (lseek(f, 0x6200, SEEK_SET) != 0x6200) {
    printf("ERROR: Seek to POS_CMD failed.\n");
    return 0;
  }
  buff[0] = 8;
  buff[1] = 'H';
  buff[2] = 'A';
  buff[3] = 'C';
  buff[4] = 'K';
  memset(&buff[5], 0, 4);
  wrote_bytes = write(f, buff, 0x200);
  if (wrote_bytes != 0x200) {
    printf("ERROR: Write failed for command hack.\n");
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<hack_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    $0x6200,%esi
call   1050 <lseek@plt>
cmp    $0x6200,%eax
je     1188 <hack_frame+0x48>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <hack_frame+0xc3>
mov    -0x10(%rbp),%rax
movb   $0x8,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x48,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x41,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x43,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x4b,0x4(%rax)
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x200,-0x14(%rbp)
je     11fc <hack_frame+0xbc>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1203 <hack_frame+0xc3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hack_frame>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    $0x6200,%esi
call   1050 <lseek@plt>
cmp    $0x6200,%eax
jne    11a3 <hack_frame+0x63>
movl   $0x43414808,(%rbx)
movb   $0x4b,0x4(%rbx)
lea    0x5(%rbx),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1040 <write@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x200,%ecx
je     11b1 <hack_frame+0x71>
lea    0xe5f(%rip),%rdi
jmp    11aa <hack_frame+0x6a>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [32 x i8] c"ERROR: Seek to POS_CMD failed.\0A\00"
@.str.1 = [39 x i8] c"ERROR: Write failed for command hack.\0A\00"
define i32 @hack_frame(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = load i32, i32* @SEEK_SET
%9 = call i32 @lseek(i32 %7, i32 25088, i32 %8)
%10 = icmp ne i32 %9, 25088
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %35
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 8, i8* %15
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 72, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 2
store i8 65, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 3
store i8 67, i8* %21
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 4
store i8 75, i8* %23
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 5
%26 = call i32 @memset(i8* %25, i32 0, i32 4)
%27 = load i32, i32* %4
%28 = load i8*, i8** %5
%29 = call i32 @write(i32 %27, i8* %28, i32 512)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 512
br i1 %31, label %32, label %34
32: ; preds = %13
%33 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %35
34: ; preds = %13
store i32 1, i32* %3
br label %35
35: ; preds = %34, %32, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@str = [38 x i8] c"ERROR: Write failed for command hack.\00"
@str.2 = [31 x i8] c"ERROR: Seek to POS_CMD failed.\00"
define i32 @hack_frame(i32 %0, i8* %1) {
%3 = load i32, i32* @SEEK_SET
%4 = tail call i32 @lseek(i32 %0, i32 25088, i32 %3)
%5 = icmp eq i32 %4, 25088
br i1 %5, label %6, label %15
6: ; preds = %2
store i8 8, i8* %1
%7 = getelementptr inbounds i8, i8* %1, i64 1
store i8 72, i8* %7
%8 = getelementptr inbounds i8, i8* %1, i64 2
store i8 65, i8* %8
%9 = getelementptr inbounds i8, i8* %1, i64 3
store i8 67, i8* %9
%10 = getelementptr inbounds i8, i8* %1, i64 4
store i8 75, i8* %10
%11 = getelementptr inbounds i8, i8* %1, i64 5
%12 = tail call i32 @memset(i8* %11, i32 0, i32 4)
%13 = tail call i32 @write(i32 %0, i8* %1, i32 512)
%14 = icmp eq i32 %13, 512
br i1 %14, label %18, label %15
15: ; preds = %6, %2
%16 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0), %6 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %15, %6
%19 = phi i32 [ 1, %6 ], [ 0, %15 ]
ret i32 %19
}