#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*/ AF_LOCAL;
int /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ SOCK_STREAM;
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
int /*<<< orphan*/ sysf_printf(char *, char *);
int sync_init(int fd[2]) {
  int rc;
  rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, fd);
  do {
    if ((rc < 0))
      sysf_printf("Error creating socket pair", "");
  } while (0);
  rc = fcntl(fd[0], F_SETFD, FD_CLOEXEC);
  do {
    if ((rc < 0))
      sysf_printf("Error setting FD_CLOEXEC", "");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<sync_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
xor    %edx,%edx
call   1040 <socketpair@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1179 <sync_init+0x49>
lea    0xe93(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1050 <sysf_printf@plt>
jmp    117e <sync_init+0x4e>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11bb <sync_init+0x8b>
lea    0xe6c(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <sysf_printf@plt>
jmp    11c0 <sync_init+0x90>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_init>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1040 <socketpair@plt>
test   %eax,%eax
jns    1167 <sync_init+0x37>
lea    0xea5(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1050 <sysf_printf@plt>
mov    (%rbx),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
test   %eax,%eax
jns    1197 <sync_init+0x67>
lea    0xe90(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1050 <sysf_printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"Error creating socket pair\00"
@.str.1 = [1 x i8] zeroinitializer
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.2 = [25 x i8] c"Error setting FD_CLOEXEC\00"
define i32 @sync_init(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32, i32* @AF_LOCAL
%5 = load i32, i32* @SOCK_STREAM
%6 = load i32*, i32** %2
%7 = call i32 @socketpair(i32 %4, i32 %5, i32 0, i32* %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @sysf_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
br label %14
14: ; preds = %13
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = load i32, i32* @F_SETFD
%19 = load i32, i32* @FD_CLOEXEC
%20 = call i32 @fcntl(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %14
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @sysf_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
br label %27
27: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@AF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"Error creating socket pair\00"
@.str.1 = [1 x i8] zeroinitializer
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.2 = [25 x i8] c"Error setting FD_CLOEXEC\00"
define i32 @sync_init(i32* %0) {
%2 = load i32, i32* @AF_LOCAL
%3 = load i32, i32* @SOCK_STREAM
%4 = tail call i32 @socketpair(i32 %2, i32 %3, i32 0, i32* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %0
%10 = load i32, i32* @F_SETFD
%11 = load i32, i32* @FD_CLOEXEC
%12 = tail call i32 @fcntl(i32 %9, i32 %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
ret i32 0
}