#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*/ close(int);
int write(int, char *, int);
int sync_pipe_notify(int fd[]) {
  char buf = 'A';
  int r;
  if (fd[0] != -1) {
    close(fd[0]);
    fd[0] = -1;
  }
  r = write(fd[1], &buf, 1);
  if (r != 1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<sync_pipe_notify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x41,-0x11(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     1152 <sync_pipe_notify+0x32>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1180 <sync_pipe_notify+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <sync_pipe_notify+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_pipe_notify>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x41,0xf(%rsp)
mov    (%rdi),%edi
cmp    $0xffffffff,%edi
je     113f <sync_pipe_notify+0x1f>
call   1040 <close@plt>
movl   $0xffffffff,(%rbx)
mov    0x4(%rbx),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @sync_pipe_notify(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %3
store i8 65, i8* %4
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
store i32 -1, i32* %16
br label %17
17: ; preds = %10, %1
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = call i32 @write(i32 %20, i8* %4, i32 1)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %2
br label %26
25: ; preds = %17
store i32 0, i32* %2
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @sync_pipe_notify(i32* nocapture %0) {
%2 = alloca i8
store i8 65, i8* %2
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @close(i32 %3)
store i32 -1, i32* %0
br label %7
7: ; preds = %5, %1
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = call i32 @write(i32 %9, i8* %2, i32 1)
%11 = icmp ne i32 %10, 1
%12 = sext i1 %11 to i32
ret i32 %12
}