#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 const *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int main(int argc, const char **argv, const char **env) {
  if (argc != 2) {
    printf("usage: %s output_file\n", argv[0]);
    return 1;
  }
  FILE *f = fopen(argv[1], "w");
  if (f == NULL) {
    perror("fopen");
    return 2;
  }
  const char **v = env;
  while (*v != NULL) {
    fputs(*v, f);
    fputc('\0', f);
    v++;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <main+0x7e>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1230 <main+0xd0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1220 <main+0xc0>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11e6 <main+0x86>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11ba <main+0x5a>
mov    %rdx,%rbx
mov    0x8(%rsi),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d6 <main+0x76>
mov    %rax,%r14
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11ae <main+0x4e>
add    $0x8,%rbx
mov    %r14,%rsi
call   1050 <fputs@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1190 <main+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11ce <main+0x6e>
mov    (%rsi),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    11ce <main+0x6e>

LLVM IR (-O0):
@.str = [23 x i8] c"usage: %s output_file\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %4
br label %44
17: ; preds = %3
%18 = load i8**, i8*** %6
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %4
br label %44
26: ; preds = %17
%27 = load i8**, i8*** %7
store i8** %27, i8*** %9
br label %28
28: ; preds = %32, %26
%29 = load i8**, i8*** %9
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i8**, i8*** %9
%34 = load i8*, i8** %33
%35 = load i32*, i32** %8
%36 = call i32 @fputs(i8* %34, i32* %35)
%37 = load i32*, i32** %8
%38 = call i32 @fputc(i8 signext 0, i32* %37)
%39 = load i8**, i8*** %9
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %9
br label %28
41: ; preds = %28
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %4
br label %44
44: ; preds = %41, %24, %12
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [23 x i8] c"usage: %s output_file\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture %2) {
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %28
8: ; preds = %3
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = icmp eq i8* %14, null
br i1 %15, label %26, label %18
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
18: ; preds = %13, %18
%19 = phi i8* [ %24, %18 ], [ %14, %13 ]
%20 = phi i8** [ %23, %18 ], [ %2, %13 ]
%21 = tail call i32 @fputs(i8* %19, i32* %11)
%22 = tail call i32 @fputc(i8 signext 0, i32* %11)
%23 = getelementptr inbounds i8*, i8** %20, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = tail call i32 @fclose(i32* %11)
br label %28
28: ; preds = %16, %26, %5
%29 = phi i32 [ 1, %5 ], [ 2, %16 ], [ 0, %26 ]
ret i32 %29
}