#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int main(void) {
  FILE *src, *dst;
  char buf[256];
  if ((src = fopen("infile.txt", "r")) == NULL) {
    exit(1);
  }
  if ((dst = fopen("outfile.txt", "w")) == NULL) {
    exit(2);
  }
  while ((fgets(buf, 256, src)) != NULL) {
    fputs(buf, dst);
  }
  fclose(src);
  fclose(dst);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118d <main+0x3d>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe79(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b8 <main+0x68>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    11bd <main+0x6d>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f1 <main+0xa1>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
jmp    11bd <main+0x6d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    117e <main+0x2e>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %rax,%r14
lea    0xe85(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11a3 <main+0x53>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x90>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"infile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"outfile.txt\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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* %10, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %9
br label %15
15: ; preds = %20, %14
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = load i32*, i32** %2
%18 = call i32* @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = load i32*, i32** %3
%23 = call i32 @fputs(i8* %21, i32* %22)
br label %15
24: ; preds = %15
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"infile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"outfile.txt\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %19, label %15
13: ; preds = %7
%14 = tail call i32 @exit(i32 2)
unreachable
15: ; preds = %10, %15
%16 = call i32 @fputs(i8* %2, i32* %8)
%17 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %15
19: ; preds = %15, %10
%20 = call i32 @fclose(i32* %3)
%21 = call i32 @fclose(i32* %8)
%22 = call i32 @exit(i32 0)
unreachable
}