#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 /*<<< orphan*/ O_APPEND;
int close(int);
int dwrite_log(int, char const *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pwrite_log(const char *path, const char *msg) {
  int fd, ret;
  fd = open(path, O_APPEND);
  if (fd == -1) {
    perror("pwrite_log|open()");
    return 1;
  }
  ret = dwrite_log(fd, msg);
  if (close(fd) == -1) {
    perror("pwrite_log|close()");
    return 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<pwrite_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1187 <pwrite_log+0x47>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <pwrite_log+0x85>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <dwrite_log@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11bf <pwrite_log+0x7f>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <pwrite_log+0x85>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwrite_log>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     117c <pwrite_log+0x3c>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <dwrite_log@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     1185 <pwrite_log+0x45>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7d(%rip),%rdi
jmp    118c <pwrite_log+0x4c>
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    1173 <pwrite_log+0x33>

LLVM IR (-O0):
@O_APPEND = global i32 0
@.str = [18 x i8] c"pwrite_log|open()\00"
@.str.1 = [19 x i8] c"pwrite_log|close()\00"
define i32 @pwrite_log(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_APPEND
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %26
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @dwrite_log(i32 %16, i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %26
24: ; preds = %15
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %22, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@O_APPEND = global i32 0
@.str = [18 x i8] c"pwrite_log|open()\00"
@.str.1 = [19 x i8] c"pwrite_log|close()\00"
define i32 @pwrite_log(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_APPEND
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @dwrite_log(i32 %4, i8* %1)
%8 = tail call i32 @close(i32 %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %6, %2
%11 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %6 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %7, %6 ], [ 1, %10 ]
ret i32 %14
}