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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int main() {
  int buf[20];
  FILE *fp = fopen("./hello.c", "r"), *fp1 = fopen("./b.txt", "a+");
  fread(buf, sizeof(buf), 2, fp);
  fwrite(buf, sizeof(buf), 1, fp1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x68(%rbp)
lea    0xeaf(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x70(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rcx
mov    $0x50,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
lea    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rcx
mov    $0x50,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xec0(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
lea    0xeb6(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x50,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"./hello.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"./b.txt\00"
@.str.3 = [3 x i8] c"a+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = 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* %5, i32** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %4
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i32 @fread(i32* %7, i32 80, i32 2, i32* %8)
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i32 @fwrite(i32* %10, i32 80, i32 1, i32* %11)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"./hello.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"./b.txt\00"
@.str.3 = [3 x i8] c"a+\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%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 ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%6 = call i32 @fread(i32* %5, i32 80, i32 2, i32* %3)
%7 = call i32 @fwrite(i32* %5, i32 80, i32 1, i32* %4)
ret i32 0
}