#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int main(void) {
  FILE *fin, *fout;
  char buf[512];
  int i;
  fin = fopen("test1.img", "r");
  fout = fopen("test1good.img", "w");
  for (i = 0; i < 800; i++) {
    fread(buf, 512, 1, fin);
    fwrite(buf, 512, 1, fout);
    fseek(fin, 1, SEEK_CUR);
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x224(%rbp)
cmpl   $0x320,-0x224(%rbp)
jge    1209 <main+0xb9>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1050 <fseek@plt>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    119a <main+0x4a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe90(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    $0x320,%ebp
mov    %rsp,%r15
mov    0x2e4e(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <fseek@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"test1.img\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"test1good.img\00"
@.str.3 = [2 x i8] c"w\00"
@SEEK_CUR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [512 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
store i32 0, i32* %5
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 800
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fread(i8* %12, i32 512, i32 1, i32* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @fwrite(i8* %15, i32 512, i32 1, i32* %16)
%18 = load i32*, i32** %2
%19 = load i32, i32* @SEEK_CUR
%20 = call i32 @fseek(i32* %18, i32 1, i32 %19)
br label %21
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %8
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"test1.img\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"test1good.img\00"
@.str.3 = [2 x i8] c"w\00"
@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 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %11, %5 ]
%7 = call i32 @fread(i8* %2, i32 512, i32 1, i32* %3)
%8 = call i32 @fwrite(i8* %2, i32 512, i32 1, i32* %4)
%9 = load i32, i32* @SEEK_CUR
%10 = tail call i32 @fseek(i32* %3, i32 1, i32 %9)
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, 800
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call i32 @fclose(i32* %3)
%15 = tail call i32 @fclose(i32* %4)
ret i32 0
}