#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(void) {
  FILE *src, *dst;
  char buf[256];
  if ((src = fopen("infile.txt", "r")) == NULL) {
    fprintf(stderr, "Error: %i\n", errno);
    exit(1);
  }
  if ((dst = fopen("outfile.txt", "w")) == NULL) {
    fprintf(stderr, "Error: %i\n", errno);
    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    0xe87(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x5b>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe56(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1204 <main+0xa4>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
lea    0xe18(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
jmp    1209 <main+0xa9>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123d <main+0xdd>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
jmp    1209 <main+0xa9>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe8d(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11ac <main+0x4c>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%r14
lea    0xe62(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11ef <main+0x8f>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
lea    0xe2d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1230 <main+0xd0>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
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    1210 <main+0xb0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

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