#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*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
void write_int(const char *path, int value) {
  FILE *f;
  f = fopen(path, "w");
  if (f) {
    if (fprintf(f, "%i", value)) {
      fclose(f);
      return;
    } else {
      fclose(f);
      error("Error writing\n");
    }
  } else {
    error("Error writing\n");
  }
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b3 <write_int+0x73>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
je     1199 <write_int+0x59>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11bf <write_int+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe5c(%rip),%rdi
call   1050 <error@plt>
jmp    11bf <write_int+0x7f>
lea    0xe4b(%rip),%rdi
call   1050 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1181 <write_int+0x41>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rbp,%rbp
je     1181 <write_int+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <error@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Error writing\0A\00"
define void @write_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = load i32, i32* %4
%13 = call i64 @fprintf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %5
%17 = call i32 @fclose(i32* %16)
br label %25
18: ; preds = %10
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
%21 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %18
br label %25
23: ; preds = %2
%24 = call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %15, %23, %22
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Error writing\0A\00"
define void @write_int(i8* nocapture %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 %9, label %5
5: ; preds = %2
%6 = tail call i64 @fprintf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%7 = icmp eq i64 %6, 0
%8 = tail call i32 @fclose(i32* %3)
br i1 %7, label %9, label %11
9: ; preds = %2, %5
%10 = tail call i32 @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
ret void
}