#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 */
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void copy_file(FILE *img, FILE *sys) {
  char buf[512];
  for (int i = 1; i < 80; i++) {
    fseek(img, 18 * 2 * 512 * i, 0);
    for (int j = 0; j < 18; j++) {
      if (fread(buf, 1, 512, sys))
        fwrite(buf, 1, 512, img);
      else
        return;
    }
  }
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x214(%rbp)
cmpl   $0x50,-0x214(%rbp)
jge    1200 <copy_file+0xd0>
mov    -0x8(%rbp),%rdi
imul   $0x4800,-0x214(%rbp),%esi
xor    %edx,%edx
call   1040 <fseek@plt>
movl   $0x0,-0x218(%rbp)
cmpl   $0x12,-0x218(%rbp)
jge    11e7 <copy_file+0xb7>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     11c9 <copy_file+0x99>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1050 <fwrite@plt>
jmp    11ce <copy_file+0x9e>
jmp    1200 <copy_file+0xd0>
jmp    11d3 <copy_file+0xa3>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    1179 <copy_file+0x49>
jmp    11ec <copy_file+0xbc>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    114d <copy_file+0x1d>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%r12d
mov    %rsp,%r15
mov    %r12d,%eax
shl    $0xb,%eax
lea    (%rax,%rax,8),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <fseek@plt>
mov    $0x12,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11ae <copy_file+0x7e>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0xffffffff,%ebp
jne    1170 <copy_file+0x40>
add    $0x1,%r12d
cmp    $0x50,%r12d
jne    114e <copy_file+0x1e>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @copy_file(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 1, i32* %6
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 80
br i1 %10, label %11, label %37
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = load i32, i32* %6
%14 = mul nsw i32 18432, %13
%15 = call i32 @fseek(i32* %12, i32 %14, i32 0)
store i32 0, i32* %7
br label %16
16: ; preds = %30, %11
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 18
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i64 @fread(i8* %20, i32 1, i32 512, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %3
%27 = call i32 @fwrite(i8* %25, i32 1, i32 512, i32* %26)
br label %29
28: ; preds = %19
br label %37
29: ; preds = %24
br label %30
30: ; preds = %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %16
33: ; preds = %16
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %8
37: ; preds = %28, %8
ret void
}

LLVM IR (-O2):
define void @copy_file(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %17
%6 = phi i32 [ 1, %2 ], [ %18, %17 ]
%7 = mul nuw nsw i32 %6, 18432
%8 = tail call i32 @fseek(i32* %0, i32 %7, i32 0)
br label %9
9: ; preds = %5, %13
%10 = phi i32 [ 0, %5 ], [ %15, %13 ]
%11 = call i64 @fread(i8* %4, i32 1, i32 512, i32* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = call i32 @fwrite(i8* %4, i32 1, i32 512, i32* %0)
%15 = add nuw nsw i32 %10, 1
%16 = icmp eq i32 %15, 18
br i1 %16, label %17, label %9
17: ; preds = %13
%18 = add nuw nsw i32 %6, 1
%19 = icmp eq i32 %18, 80
br i1 %19, label %20, label %5
20: ; preds = %17, %9
ret void
}