#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 BUFSIZ;
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 *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  printf("BUFSUZ is currently: %d\n", BUFSIZ);
  FILE *from, *to;
  char line[BUFSIZ];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s from-file to-file\n", *argv);
    exit(1);
  }
  from = fopen(argv[1], "r");
  if (from == NULL) {
    perror(argv[1]);
    exit(1);
  }
  to = fopen(argv[2], "a");
  if (to == NULL) {
    perror(argv[2]);
    exit(1);
  }
  while (fgets(line, BUFSIZ, from) != NULL) {
    fputs(line, to);
  }
  fclose(from);
  fclose(to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1208 <main+0x88>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe20(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1242 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127c <main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1281 <main+0x101>
mov    -0x38(%rbp),%rdi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12b3 <main+0x133>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1281 <main+0x101>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e3d(%rip),%r13
mov    0x0(%r13),%esi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%r15d
jne    1242 <main+0xc2>
mov    0x8(%r14),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1264 <main+0xe4>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     126a <main+0xea>
mov    %rax,%r12
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1221 <main+0xa1>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fputs@plt>
jmp    1200 <main+0x80>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdc4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rdi
jmp    126e <main+0xee>
mov    0x10(%r14),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"BUFSUZ is currently: %d\0A\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s from-file to-file\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @perror(i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %7
%42 = load i32*, i32** %7
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %37
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @perror(i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %37
br label %51
51: ; preds = %56, %50
%52 = load i32, i32* @BUFSIZ
%53 = load i32*, i32** %6
%54 = call i32* @fgets(i8* %15, i32 %52, i32* %53)
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32*, i32** %7
%58 = call i32 @fputs(i8* %15, i32* %57)
br label %51
59: ; preds = %51
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
%64 = load i8*, i8** %8
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [25 x i8] c"BUFSUZ is currently: %d\0A\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s from-file to-file\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp eq i32 %0, 3
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i32 @perror(i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32, i32* @BUFSIZ
%30 = call i32* @fgets(i8* %7, i32 %29, i32* %17)
%31 = icmp eq i32* %30, null
br i1 %31, label %41, label %36
32: ; preds = %23
%33 = load i8*, i8** %24
%34 = tail call i32 @perror(i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %28, %36
%37 = call i32 @fputs(i8* %7, i32* %26)
%38 = load i32, i32* @BUFSIZ
%39 = call i32* @fgets(i8* %7, i32 %38, i32* %17)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %36
41: ; preds = %36, %28
%42 = call i32 @fclose(i32* %17)
%43 = call i32 @fclose(i32* %26)
ret i32 0
}