#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int getchar();
main(int c, char **argv) {
  FILE *f = fopen(argv[1], "w");
  int i;
  while ((i = getchar()) != -1) {
    fwrite(&i, 1, sizeof(int), f);
  }
  fclose(f);
}


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    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     119d <main+0x5d>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <fwrite@plt>
jmp    116e <main+0x2e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     1195 <main+0x55>
lea    0x4(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
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 1
%10 = load i8*, i8** %9
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %15, %2
%13 = call i32 (...) @getchar()
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32*, i32** %6
%17 = call i32 @fwrite(i32* %7, i32 1, i32 4, i32* %16)
br label %12
18: ; preds = %12
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 (...) @getchar()
store i32 %8, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %2, %10
%11 = call i32 @fwrite(i32* %3, i32 1, i32 4, i32* %6)
%12 = tail call i32 (...) @getchar()
store i32 %12, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %10
14: ; preds = %10, %2
%15 = tail call i32 @fclose(i32* %6)
ret i32 0
}