#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*/ abort();
int connect_socket(char const *, int);
int /*<<< orphan*/ start_server(char const *, char const *, char const *);
int connect_and_serve(const char *socket_path, const char *event_path,
                      const char *exec_path) {
  int sock = connect_socket(socket_path, 0);
  if (sock == -1) {
    start_server(socket_path, event_path, exec_path);
    sock = connect_socket(socket_path, 1);
  }
  if (sock == -1)
    abort();
  return sock;
}


x86 assembly (clang, -O0):
<connect_and_serve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1040 <connect_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117e <connect_and_serve+0x4e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <start_server@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <connect_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    118f <connect_and_serve+0x5f>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_and_serve>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %esi,%esi
call   1040 <connect_socket@plt>
cmp    $0xffffffff,%eax
jne    116a <connect_and_serve+0x3a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <start_server@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <connect_socket@plt>
cmp    $0xffffffff,%eax
je     1170 <connect_and_serve+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @connect_and_serve(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i32 @connect_socket(i8* %8, i32 0)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = call i32 @start_server(i8* %13, i8* %14, i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @connect_socket(i8* %17, i32 1)
store i32 %18, i32* %7
br label %19
19: ; preds = %12, %3
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %19
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
define i32 @connect_and_serve(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @connect_socket(i8* %0, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i32 @start_server(i8* %0, i8* %1, i8* %2)
%8 = tail call i32 @connect_socket(i8* %0, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %3, %6
%13 = phi i32 [ %8, %6 ], [ %4, %3 ]
ret i32 %13
}