#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);
scalar_t__ file_write(int, char *, int);
int file_write_str(char *path, char *buf, int len) {
  int fd;
  fd = file_open(path, O_SYNC | O_WRONLY);
  if (fd < 0) {
    return EXIT_FAILURE;
  }
  if (file_write(fd, buf, len) < 0) {
    return EXIT_FAILURE;
  }
  if (file_close(fd) < 0) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<file_write_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
call   1030 <file_open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    117c <file_write_str+0x4c>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <file_write_str+0xa5>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <file_write@plt>
cmp    $0x0,%rax
jge    11a6 <file_write_str+0x76>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <file_write_str+0xa5>
mov    -0x20(%rbp),%edi
call   1040 <file_close@plt>
cmp    $0x0,%rax
jge    11c9 <file_write_str+0x99>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <file_write_str+0xa5>
mov    0x2e00(%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_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    0x2ea4(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1030 <file_open@plt>
mov    0x2e7d(%rip),%rbx
test   %eax,%eax
js     118f <file_write_str+0x5f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <file_write@plt>
test   %rax,%rax
js     118f <file_write_str+0x5f>
mov    %ebp,%edi
call   1040 <file_close@plt>
test   %rax,%rax
jns    1188 <file_write_str+0x58>
mov    0x2e52(%rip),%rbx
jmp    118f <file_write_str+0x5f>
mov    0x2e41(%rip),%rbx
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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_str(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* @O_SYNC
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %10, %11
%13 = call i32 @file_open(i8* %9, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %4
br label %34
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i64 @file_write(i32 %19, i8* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %4
br label %34
26: ; preds = %18
%27 = load i32, i32* %8
%28 = call i64 @file_close(i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %4
br label %34
32: ; preds = %26
%33 = load i32, i32* @EXIT_SUCCESS
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %30, %24, %16
%35 = load i32, i32* %4
ret i32 %35
}

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_str(i8* %0, i8* %1, i32 %2) {
%4 = load i32, i32* @O_SYNC
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %5, %4
%7 = tail call i32 @file_open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = tail call i64 @file_write(i32 %7, i8* %1, i32 %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i64 @file_close(i32 %7)
%14 = icmp slt i64 %13, 0
%15 = select i1 %14, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %16
16: ; preds = %12, %9, %3
%17 = phi i32* [ @EXIT_FAILURE, %3 ], [ @EXIT_FAILURE, %9 ], [ %15, %12 ]
%18 = load i32, i32* %17
ret i32 %18
}