#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 */

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_SYNC;
int O_WRONLY;
scalar_t__ file_close(int);
int file_open(char *, int);
int file_write_int_fd(int, int);
int file_write_int_path(char *path, int val) {
  int fd, ret;
  fd = file_open(path, O_SYNC | O_WRONLY);
  if (fd < 0) {
    return EXIT_FAILURE;
  }
  ret = file_write_int_fd(fd, val);
  if (file_close(fd) < 0 || ret == EXIT_FAILURE) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<file_write_int_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
call   1030 <file_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1178 <file_write_int_path+0x48>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <file_write_int_path+0x97>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <file_write_int_fd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <file_close@plt>
cmp    $0x0,%rax
jl     11aa <file_write_int_path+0x7a>
mov    -0x1c(%rbp),%eax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
jne    11bb <file_write_int_path+0x8b>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <file_write_int_path+0x97>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_write_int_path>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2eac(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1030 <file_open@plt>
test   %eax,%eax
js     1182 <file_write_int_path+0x52>
mov    %eax,%ebp
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <file_write_int_fd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <file_close@plt>
mov    0x2e6d(%rip),%rdx
mov    %rdx,%rcx
cmp    (%rdx),%ebx
je     1179 <file_write_int_path+0x49>
mov    0x2e57(%rip),%rcx
test   %rax,%rax
cmovs  %rdx,%rcx
jmp    1189 <file_write_int_path+0x59>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_SYNC = global i32 0
@O_WRONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_write_int_path(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
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_SYNC
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %9, %10
%12 = call i32 @file_open(i8* %8, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = call i32 @file_write_int_fd(i32 %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = call i64 @file_close(i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i32, i32* %7
%26 = load i32, i32* @EXIT_FAILURE
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24, %17
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %32
30: ; preds = %24
%31 = load i32, i32* @EXIT_SUCCESS
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %28, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@O_SYNC = global i32 0
@O_WRONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_write_int_path(i8* %0, i32 %1) {
%3 = load i32, i32* @O_SYNC
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = tail call i32 @file_open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = tail call i32 @file_write_int_fd(i32 %6, i32 %1)
%10 = tail call i64 @file_close(i32 %6)
%11 = icmp slt i64 %10, 0
%12 = load i32, i32* @EXIT_FAILURE
%13 = icmp eq i32 %9, %12
%14 = select i1 %11, i1 true, i1 %13
%15 = select i1 %14, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %16
16: ; preds = %8, %2
%17 = phi i32* [ @EXIT_FAILURE, %2 ], [ %15, %8 ]
%18 = load i32, i32* %17
ret i32 %18
}