#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 O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int pd, file_desc;
  char buffer[100 * 1024];
  memset(buffer, 0, 100 * 1024);
  printf("\nReading Image...");
  file_desc = open("dist/image.bin", O_RDONLY);
  read(file_desc, buffer, 100 * 1024);
  close(file_desc);
  printf("\nWriting Image...");
  pd = open("/dev/sdb", O_WRONLY | O_TRUNC);
  write(pd, buffer, 100 * 1024);
  close(pd);
  printf("\nImage Burnt. :-) Enjoy it!\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x19010,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x19010(%rbp),%rdi
xor    %esi,%esi
mov    $0x19000,%edx
call   1050 <memset@plt>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x19010(%rbp),%rsi
mov    $0x19000,%edx
call   1070 <read@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
lea    0xe49(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x19010(%rbp),%rsi
mov    $0x19000,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x19010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x19008,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x19000,%edx
call   1060 <memset@plt>
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x19000,%edx
call   1080 <read@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    0x2df1(%rip),%rax
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x19000,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x19008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0AReading Image...\00"
@.str.1 = [15 x i8] c"dist/image.bin\00"
@O_RDONLY = global i32 0
@.str.2 = [18 x i8] c"\0AWriting Image...\00"
@.str.3 = [9 x i8] c"/dev/sdb\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [30 x i8] c"\0AImage Burnt. :-) Enjoy it!\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [102400 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [102400 x i8], [102400 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 102400)
%7 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = getelementptr inbounds [102400 x i8], [102400 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 102400)
%13 = load i32, i32* %3
%14 = call i32 @close(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = getelementptr inbounds [102400 x i8], [102400 x i8]* %4, i64 0, i64 0
%22 = call i32 @write(i32 %20, i8* %21, i32 102400)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0AReading Image...\00"
@.str.1 = [15 x i8] c"dist/image.bin\00"
@O_RDONLY = global i32 0
@.str.2 = [18 x i8] c"\0AWriting Image...\00"
@.str.3 = [9 x i8] c"/dev/sdb\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@str = [29 x i8] c"\0AImage Burnt. :-) Enjoy it!\0A\00"
define i32 @main() {
%1 = alloca [102400 x i8]
%2 = getelementptr inbounds [102400 x i8], [102400 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 102400)
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @read(i32 %6, i8* %2, i32 102400)
%8 = call i32 @close(i32 %6)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %11, %10
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = call i32 @write(i32 %13, i8* %2, i32 102400)
%15 = call i32 @close(i32 %13)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i32 0
}