#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ filecopy(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  FILE *file;
  char *program_name;
  program_name = argv[0];
  if (2 != argc) {
    fprintf(stderr, "usage: %s filename \n", program_name);
  } else {
    if (NULL == (file = fopen(argv[1], "r+b"))) {
      fprintf(stderr, "%s: can't open %s\n", program_name, argv[1]);
      return 1;
    } else {
      filecopy(stdin, file);
      fclose(file);
    }
    if (ferror(file)) {
      fprintf(stderr, "%s: error writing %s\n", program_name, argv[1]);
      return 2;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     119f <main+0x4f>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1256 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11f4 <main+0xa4>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125d <main+0x10d>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1060 <filecopy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1251 <main+0x101>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    125d <main+0x10d>
jmp    1256 <main+0x106>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    (%rsi),%r14
cmp    $0x2,%edi
jne    11c3 <main+0x73>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e1 <main+0x91>
mov    %rax,%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <filecopy@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1206 <main+0xb6>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rcx
lea    0xe7a(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%ebx
jmp    1208 <main+0xb8>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1208 <main+0xb8>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rcx
lea    0xe24(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    1208 <main+0xb8>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"usage: %s filename \0A\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [19 x i8] c"%s: can't open %s\0A\00"
@stdin = global i32 0
@.str.3 = [22 x i8] c"%s: error writing %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
store i8* %10, i8** %7
%11 = load i32, i32* %4
%12 = icmp ne i32 2, %11
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %7
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %48
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp eq i32* null, %21
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %28)
store i32 1, i32* %3
br label %49
30: ; preds = %17
%31 = load i32, i32* @stdin
%32 = load i32*, i32** %6
%33 = call i32 @filecopy(i32 %31, i32* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %30
%37 = load i32*, i32** %6
%38 = call i64 @ferror(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %7
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %45)
store i32 2, i32* %3
br label %49
47: ; preds = %36
br label %48
48: ; preds = %47, %13
store i32 0, i32* %3
br label %49
49: ; preds = %48, %40, %23
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"usage: %s filename \0A\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [19 x i8] c"%s: can't open %s\0A\00"
@stdin = global i32 0
@.str.3 = [22 x i8] c"%s: error writing %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %15)
br label %27
17: ; preds = %8
%18 = load i32, i32* @stdin
%19 = tail call i32 @filecopy(i32 %18, i32* %11)
%20 = tail call i32 @fclose(i32* %11)
%21 = tail call i64 @ferror(i32* %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %9
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %25)
br label %27
27: ; preds = %5, %17, %23, %13
%28 = phi i32 [ 1, %13 ], [ 2, %23 ], [ 0, %17 ], [ 0, %5 ]
ret i32 %28
}