#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int record(const char *filename, unsigned int score) {
  FILE *fp = fopen(filename, "w");
  if (fp == NULL) {
    fprintf(stderr, "writing '%s': %s\n", filename, strerror(errno));
    return 1;
  }
  fprintf(fp, "%u\n", score);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <record+0x77>
mov    0x2e6b(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <record+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
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):
<record>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117e <record+0x3e>
mov    %rax,%rbp
lea    0xeaf(%rip),%rsi
xor    %ebx,%ebx
mov    %rax,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11b2 <record+0x72>
mov    0x2e5b(%rip),%rax
movslq (%rax),%rbp
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe65(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"writing '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [4 x i8] c"%u\0A\00"
define i32 @record(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = load i8*, i8** %4
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
store i32 1, i32* %3
br label %25
19: ; preds = %2
%20 = load i32*, i32** %6
%21 = load i32, i32* %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %3
br label %25
25: ; preds = %19, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"writing '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [4 x i8] c"%u\0A\00"
define i32 @record(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %10)
br label %15
12: ; preds = %2
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%14 = tail call i32 @fclose(i32* %3)
br label %15
15: ; preds = %12, %5
%16 = phi i32 [ 1, %5 ], [ 0, %12 ]
ret i32 %16
}