#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(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ stderr;
FILE *aml_fio_open_for_writing(char *fn, char *source_file, int source_line) {
  FILE *f;
  if (!(f = fopen(fn, "w"))) {
    fprintf(stderr, "%s:%d: Error opening \"%s\" for writing\n", source_file,
            source_line, fn);
    exit(1);
  }
  return f;
}


x86 assembly (clang, -O0):
<aml_fio_open_for_writing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    118b <aml_fio_open_for_writing+0x5b>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aml_fio_open_for_writing>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xebc(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1153 <aml_fio_open_for_writing+0x23>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s:%d: Error opening \22%s\22 for writing\0A\00"
define i32* @aml_fio_open_for_writing(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %18, label %11
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32*, i32** %7
ret i32* %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s:%d: Error opening \22%s\22 for writing\0A\00"
define noalias i32* @aml_fio_open_for_writing(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2, i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
ret i32* %4
}