#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void copyFile() {
  char *read_path = "./list.rar";
  char *write_path = "./list2.rar";
  FILE *read_fp = fopen(read_path, "rb");
  if (read_fp == NULL) {
    printf("open read file fail");
    return;
  }
  FILE *write_fp = fopen(write_path, "wb");
  if (write_fp == NULL) {
    printf("open write file fail");
    return;
  }
  int buff[50];
  size_t len = 0;
  while ((len = fread(buff, sizeof(int), 50, read_fp)) != 0) {
    printf("read len-> %d, ", len);
    fwrite(buff, sizeof(int), len, write_fp);
  }
  fclose(read_fp);
  fclose(write_fp);
}


x86 assembly (clang, -O0):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
lea    0xe9e(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <copyFile+0x53>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1253 <copyFile+0x103>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d5 <copyFile+0x85>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1253 <copyFile+0x103>
movq   $0x0,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x32,%edx
call   1030 <fread@plt>
mov    %rax,-0xf8(%rbp)
cmp    $0x0,%rax
je     1241 <copyFile+0xf1>
mov    -0xf8(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1070 <fwrite@plt>
jmp    11e0 <copyFile+0x90>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd0,%rsp
lea    0xe99(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122d <copyFile+0xdd>
mov    %rax,%r12
lea    0xe85(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1236 <copyFile+0xe6>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x32,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     120d <copyFile+0xbd>
mov    %rax,%rbx
lea    0xe84(%rip),%r15
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x32,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d0 <copyFile+0x80>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xde6(%rip),%rdi
jmp    123d <copyFile+0xed>
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"./list.rar\00"
@.str.1 = [12 x i8] c"./list2.rar\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"open read file fail\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [21 x i8] c"open write file fail\00"
@.str.6 = [16 x i8] c"read len-> %d, \00"
define void @copyFile() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [50 x i32]
%6 = alloca i64
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %1
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %38
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %38
20: ; preds = %13
store i64 0, i64* %6
br label %21
21: ; preds = %26, %20
%22 = getelementptr inbounds [50 x i32], [50 x i32]* %5, i64 0, i64 0
%23 = load i32*, i32** %3
%24 = call i64 @fread(i32* %22, i32 4, i32 50, i32* %23)
store i64 %24, i64* %6
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i64, i64* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 %27)
%29 = getelementptr inbounds [50 x i32], [50 x i32]* %5, i64 0, i64 0
%30 = load i64, i64* %6
%31 = load i32*, i32** %4
%32 = call i32 @fwrite(i32* %29, i32 4, i64 %30, i32* %31)
br label %21
33: ; preds = %21
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %4
%37 = call i32 @fclose(i32* %36)
br label %38
38: ; preds = %33, %18, %11
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"./list.rar\00"
@.str.1 = [12 x i8] c"./list2.rar\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [20 x i8] c"open read file fail\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [21 x i8] c"open write file fail\00"
@.str.6 = [16 x i8] c"read len-> %d, \00"
define void @copyFile() {
%1 = alloca [50 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %25
6: ; preds = %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %25
11: ; preds = %6
%12 = bitcast [50 x i32]* %1 to i8*
%13 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 0
%14 = call i64 @fread(i32* %13, i32 4, i32 50, i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %11, %16
%17 = phi i64 [ %20, %16 ], [ %14, %11 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 %17)
%19 = call i32 @fwrite(i32* %13, i32 4, i64 %17, i32* %7)
%20 = call i64 @fread(i32* %13, i32 4, i32 50, i32* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %16, %11
%23 = tail call i32 @fclose(i32* %2)
%24 = tail call i32 @fclose(i32* %7)
br label %25
25: ; preds = %9, %22, %4
ret void
}