#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
int write_int_file(char *name, int val) {
  int rv = 0;
  FILE *f;
  f = fopen(name, "wb");
  if (f == NULL) {
    return -1;
  }
  if (fprintf(f, "%d", val) == 0) {
    rv = -1;
  }
  fclose(f);
  return rv;
}


x86 assembly (clang, -O0):
<write_int_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <write_int_file+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <write_int_file+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jne    1195 <write_int_file+0x65>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int_file>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116a <write_int_file+0x3a>
mov    %rax,%rbx
lea    0xeb3(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    116f <write_int_file+0x3f>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @write_int_file(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, 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 = sext i1 %7 to i32
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ %8, %5 ], [ -1, %2 ]
ret i32 %11
}