#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 */
struct ws_server {
  int dummy;
};

/* Variables and functions */
struct ws_server *create_server_ws(int (*)(struct ws_client *));
scalar_t__ register_signals_ws();
scalar_t__ run_loop_ws(struct ws_server *);
scalar_t__ setup_tls_ws(struct ws_server *);
int /*<<< orphan*/ shutdown_server_ws(struct ws_server *);
scalar_t__ startup_server(struct ws_server *, char *);
int register_client_handler_server(int (*client_data_fn)(struct ws_client *c),
                                   char *port) {
  struct ws_server *s;
  if (register_signals_ws() < 0) {
    return -1;
  }
  s = create_server_ws(client_data_fn);
  if (s == NULL) {
    return -1;
  }
  if (setup_tls_ws(s) < 0) {
    shutdown_server_ws(s);
    return -1;
  }
  if (startup_server(s, port) < 0) {
    shutdown_server_ws(s);
    return -1;
  }
  if (run_loop_ws(s) < 0) {
    shutdown_server_ws(s);
    return -1;
  }
  shutdown_server_ws(s);
  return 0;
}


x86 assembly (clang, -O0):
<register_client_handler_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <register_signals_ws@plt>
cmp    $0x0,%rax
jge    118d <register_client_handler_server+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <register_client_handler_server+0xdd>
mov    -0x10(%rbp),%rdi
call   1070 <create_server_ws@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <register_client_handler_server+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <register_client_handler_server+0xdd>
mov    -0x20(%rbp),%rdi
call   1040 <setup_tls_ws@plt>
cmp    $0x0,%rax
jge    11d9 <register_client_handler_server+0x79>
mov    -0x20(%rbp),%rdi
call   1080 <shutdown_server_ws@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <register_client_handler_server+0xdd>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <startup_server@plt>
cmp    $0x0,%rax
jge    1205 <register_client_handler_server+0xa5>
mov    -0x20(%rbp),%rdi
call   1080 <shutdown_server_ws@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <register_client_handler_server+0xdd>
mov    -0x20(%rbp),%rdi
call   1030 <run_loop_ws@plt>
cmp    $0x0,%rax
jge    122d <register_client_handler_server+0xcd>
mov    -0x20(%rbp),%rdi
call   1080 <shutdown_server_ws@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <register_client_handler_server+0xdd>
mov    -0x20(%rbp),%rdi
call   1080 <shutdown_server_ws@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_client_handler_server>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <register_signals_ws@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11cb <register_client_handler_server+0x6b>
mov    %rbx,%rdi
call   1070 <create_server_ws@plt>
test   %rax,%rax
je     11cb <register_client_handler_server+0x6b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <setup_tls_ws@plt>
test   %rax,%rax
js     11c3 <register_client_handler_server+0x63>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <startup_server@plt>
test   %rax,%rax
js     11c3 <register_client_handler_server+0x63>
mov    %rbx,%rdi
call   1030 <run_loop_ws@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <shutdown_server_ws@plt>
sar    $0x3f,%r14
jmp    11cb <register_client_handler_server+0x6b>
mov    %rbx,%rdi
call   1080 <shutdown_server_ws@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ws_client = type opaque
%struct.ws_server = type { i32 }
%struct.ws_client.0 = type opaque
define i32 @register_client_handler_server(i32 (%struct.ws_client*)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32 (%struct.ws_client*)*
%5 = alloca i8*
%6 = alloca %struct.ws_server*
store i32 (%struct.ws_client*)* %0, i32 (%struct.ws_client*)** %4
store i8* %1, i8** %5
%7 = call i64 (...) @register_signals_ws()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %42
10: ; preds = %2
%11 = load i32 (%struct.ws_client*)*, i32 (%struct.ws_client*)** %4
%12 = bitcast i32 (%struct.ws_client*)* %11 to i32 (%struct.ws_client.0*)*
%13 = call %struct.ws_server* @create_server_ws(i32 (%struct.ws_client.0*)* %12)
store %struct.ws_server* %13, %struct.ws_server** %6
%14 = load %struct.ws_server*, %struct.ws_server** %6
%15 = icmp eq %struct.ws_server* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 -1, i32* %3
br label %42
17: ; preds = %10
%18 = load %struct.ws_server*, %struct.ws_server** %6
%19 = call i64 @setup_tls_ws(%struct.ws_server* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load %struct.ws_server*, %struct.ws_server** %6
%23 = call i32 @shutdown_server_ws(%struct.ws_server* %22)
store i32 -1, i32* %3
br label %42
24: ; preds = %17
%25 = load %struct.ws_server*, %struct.ws_server** %6
%26 = load i8*, i8** %5
%27 = call i64 @startup_server(%struct.ws_server* %25, i8* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load %struct.ws_server*, %struct.ws_server** %6
%31 = call i32 @shutdown_server_ws(%struct.ws_server* %30)
store i32 -1, i32* %3
br label %42
32: ; preds = %24
%33 = load %struct.ws_server*, %struct.ws_server** %6
%34 = call i64 @run_loop_ws(%struct.ws_server* %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load %struct.ws_server*, %struct.ws_server** %6
%38 = call i32 @shutdown_server_ws(%struct.ws_server* %37)
store i32 -1, i32* %3
br label %42
39: ; preds = %32
%40 = load %struct.ws_server*, %struct.ws_server** %6
%41 = call i32 @shutdown_server_ws(%struct.ws_server* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %36, %29, %21, %16, %9
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.ws_client = type opaque
%struct.ws_client.0 = type opaque
%struct.ws_server = type { i32 }
define i32 @register_client_handler_server(i32 (%struct.ws_client*)* %0, i8* %1) {
%3 = tail call i64 (...) @register_signals_ws()
%4 = icmp slt i64 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = bitcast i32 (%struct.ws_client*)* %0 to i32 (%struct.ws_client.0*)*
%7 = tail call %struct.ws_server* @create_server_ws(i32 (%struct.ws_client.0*)* %6)
%8 = icmp eq %struct.ws_server* %7, null
br i1 %8, label %24, label %9
9: ; preds = %5
%10 = tail call i64 @setup_tls_ws(%struct.ws_server* %7)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @shutdown_server_ws(%struct.ws_server* %7)
br label %24
14: ; preds = %9
%15 = tail call i64 @startup_server(%struct.ws_server* %7, i8* %1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @shutdown_server_ws(%struct.ws_server* %7)
br label %24
19: ; preds = %14
%20 = tail call i64 @run_loop_ws(%struct.ws_server* %7)
%21 = tail call i32 @shutdown_server_ws(%struct.ws_server* %7)
%22 = ashr i64 %20, 63
%23 = trunc i64 %22 to i32
br label %24
24: ; preds = %19, %5, %2, %17, %12
%25 = phi i32 [ -1, %12 ], [ -1, %17 ], [ -1, %2 ], [ -1, %5 ], [ %23, %19 ]
ret i32 %25
}