#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*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc == 1) {
    usage(stderr);
    return 1;
  }
  FILE *file;
  file = fopen(argv[1], "w+");
  if (argc == 2) {
    fprintf(file, "Hello world!");
  } else if (argc > 2) {
    for (int i = 2; i < argc; i++) {
      fprintf(file, argv[i]);
    }
  }
  fclose(file);
}


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)
cmpl   $0x1,-0x8(%rbp)
jne    117a <main+0x3a>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1204 <main+0xc4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b1 <main+0x71>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fb <main+0xbb>
cmpl   $0x2,-0x8(%rbp)
jle    11f6 <main+0xb6>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f1 <main+0xb1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <main+0x82>
jmp    11f6 <main+0xb6>
jmp    11fb <main+0xbb>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    1171 <main+0x21>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <usage@plt>
mov    $0x1,%eax
jmp    11df <main+0x8f>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
jne    11a9 <main+0x59>
lea    0xe6e(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
jmp    11d5 <main+0x85>
jle    11d5 <main+0x85>
mov    %ebp,%ebp
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <main+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"w+\00"
@.str.1 = [13 x i8] c"Hello world!\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 i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @usage(i32 %11)
store i32 1, i32* %3
br label %47
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32*, i32** %6
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %44
23: ; preds = %13
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %43
26: ; preds = %23
store i32 2, i32* %7
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32* %32, i8* %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %27
42: ; preds = %27
br label %43
43: ; preds = %42, %23
br label %44
44: ; preds = %43, %20
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %10
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"w+\00"
@.str.1 = [13 x i8] c"Hello world!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @usage(i32 %5)
br label %27
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 12, i64 1, i32* %10)
br label %25
14: ; preds = %7
%15 = icmp sgt i32 %0, 2
br i1 %15, label %16, label %25
16: ; preds = %14
%17 = zext i32 %0 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 2, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i32 @fprintf(i32* %10, i8* %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %14, %12
%26 = tail call i32 @fclose(i32* %10)
br label %27
27: ; preds = %25, %4
%28 = phi i32 [ 1, %4 ], [ 0, %25 ]
ret i32 %28
}