#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2)
    errx(EXIT_FAILURE, "Tell me the filename");
  FILE *fp = fopen(argv[1], "w");
  if (!fp)
    err(EXIT_FAILURE, "fopen");
  fprintf(fp, "Hello, world!\n");
  fclose(fp);
  exit(EXIT_SUCCESS);
}


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   $0x2,-0x8(%rbp)
je     1195 <main+0x35>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cd <main+0x6d>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <err@plt>
mov    -0x18(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     117e <main+0x1e>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1040 <errx@plt>
mov    0x8(%rbx),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ab <main+0x4b>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1050 <err@plt>
lea    0xe6b(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [21 x i8] c"Tell me the filename\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [15 x i8] c"Hello, world!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @errx(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @err(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %12
%23 = load i32*, i32** %6
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [21 x i8] c"Tell me the filename\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [15 x i8] c"Hello, world!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @errx(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @err(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %7
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 14, i64 1, i32* %10)
%17 = tail call i32 @fclose(i32* %10)
%18 = load i32, i32* @EXIT_SUCCESS
%19 = tail call i32 @exit(i32 %18)
unreachable
}