#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 scalar_t__ uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, unsigned long long);
int write_value(uint64_t value, char *filename) {
  FILE *fp;
  if (!(fp = fopen(filename, "w")) ||
      fprintf(fp, "%llu\n", (unsigned long long)value) == EOF ||
      fflush(fp) == EOF || fclose(fp) == EOF)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<write_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c4 <write_value+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
je     11c4 <write_value+0x84>
mov    -0x20(%rbp),%rdi
call   1050 <fflush@plt>
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
je     11c4 <write_value+0x84>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
jne    11d0 <write_value+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <write_value+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_value>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11a7 <write_value+0x67>
mov    %rax,%rbx
lea    0xe94(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   1040 <fprintf@plt>
mov    0x2e68(%rip),%rbp
cmp    0x0(%rbp),%rax
je     11a7 <write_value+0x67>
mov    %rbx,%rdi
call   1050 <fflush@plt>
cmp    0x0(%rbp),%rax
je     11a7 <write_value+0x67>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %r14d,%r14d
cmp    0x0(%rbp),%rax
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"%llu\0A\00"
@EOF = global i64 0
define i32 @write_value(i64 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
store i64 %0, i64* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%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 = icmp ne i32* %8, null
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = load i32*, i32** %6
%12 = load i64, i64* %4
%13 = call i64 @fprintf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %12)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %26, label %16
16: ; preds = %10
%17 = load i32*, i32** %6
%18 = call i64 @fflush(i32* %17)
%19 = load i64, i64* @EOF
%20 = icmp eq i64 %18, %19
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = call i64 @fclose(i32* %22)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %21, %16, %10, %2
store i32 1, i32* %3
br label %28
27: ; preds = %21
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"%llu\0A\00"
@EOF = global i64 0
define i32 @write_value(i64 %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i64 @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = tail call i64 @fflush(i32* %3)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = tail call i64 @fclose(i32* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %2, %5, %9
%19 = phi i32 [ 1, %9 ], [ 1, %5 ], [ 1, %2 ], [ %17, %13 ]
ret i32 %19
}