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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char boot_buf[512];
  int floppy_desc, file_desc;
  file_desc = open("../efi.img", O_RDONLY);
  read(file_desc, boot_buf, 510);
  close(file_desc);
  boot_buf[510] = 0x55;
  boot_buf[511] = 0xaa;
  floppy_desc = open("boot.img", O_RDWR);
  lseek(floppy_desc, 0, SEEK_CUR);
  write(floppy_desc, boot_buf, 512);
  close(floppy_desc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x218(%rbp)
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1fe,%edx
call   1060 <read@plt>
mov    -0x218(%rbp),%edi
call   1050 <close@plt>
movb   $0x55,-0x12(%rbp)
movb   $0xaa,-0x11(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x214(%rbp)
mov    -0x214(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x214(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    -0x214(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1fe,%edx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
movw   $0xaa55,0x1fe(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"../efi.img\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"boot.img\00"
@O_RDWR = global i32 0
@SEEK_CUR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 510)
%10 = load i32, i32* %4
%11 = call i32 @close(i32 %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 510
store i8 85, i8* %12
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 511
store i8 -86, i8* %13
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = load i32, i32* @SEEK_CUR
%18 = call i32 @lseek(i32 %16, i32 0, i32 %17)
%19 = load i32, i32* %3
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 512)
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"../efi.img\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"boot.img\00"
@O_RDWR = global i32 0
@SEEK_CUR = global i32 0
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @read(i32 %4, i8* %2, i32 510)
%6 = tail call i32 @close(i32 %4)
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 510
store i8 85, i8* %7
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 511
store i8 -86, i8* %8
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @SEEK_CUR
%12 = tail call i32 @lseek(i32 %10, i32 0, i32 %11)
%13 = call i32 @write(i32 %10, i8* %2, i32 512)
%14 = tail call i32 @close(i32 %10)
ret i32 0
}