#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_INET;
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ error_exit(char *);
int /*<<< orphan*/ sock_4(int *, int);
int /*<<< orphan*/ sock_6(int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int serv_sock(int use_ipv6, int port) {
  int sock;
  if (use_ipv6) {
    sock = socket(AF_INET6, SOCK_STREAM, 0);
    if (sock < 0)
      error_exit("creating server socket");
    sock_6(&sock, port);
  } else {
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0)
      error_exit("creating server socket");
    sock_4(&sock, port);
  }
  return sock;
}


x86 assembly (clang, -O0):
<serv_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119b <serv_sock+0x5b>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118a <serv_sock+0x4a>
lea    0xe7b(%rip),%rdi
call   1040 <error_exit@plt>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1030 <sock_6@plt>
jmp    11d9 <serv_sock+0x99>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11cd <serv_sock+0x8d>
lea    0xe38(%rip),%rdi
call   1040 <error_exit@plt>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1050 <sock_4@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serv_sock>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
test   %edi,%edi
je     1186 <serv_sock+0x46>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    1178 <serv_sock+0x38>
lea    0xe8d(%rip),%rdi
call   1040 <error_exit@plt>
lea    0xc(%rsp),%rdi
mov    %ebx,%esi
call   1030 <sock_6@plt>
jmp    11bf <serv_sock+0x7f>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    11b3 <serv_sock+0x73>
lea    0xe52(%rip),%rdi
call   1040 <error_exit@plt>
lea    0xc(%rsp),%rdi
mov    %ebx,%esi
call   1050 <sock_4@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"creating server socket\00"
@AF_INET = global i32 0
define i32 @serv_sock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i32, i32* @AF_INET6
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @error_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = load i32, i32* %4
%18 = call i32 @sock_6(i32* %5, i32 %17)
br label %30
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @error_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* %4
%29 = call i32 @sock_4(i32* %5, i32 %28)
br label %30
30: ; preds = %27, %16
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"creating server socket\00"
@AF_INET = global i32 0
define i32 @serv_sock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = load i32, i32* @AF_INET6
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @error_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = call i32 @sock_6(i32* %3, i32 %1)
br label %24
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @error_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = call i32 @sock_4(i32* %3, i32 %1)
br label %24
24: ; preds = %22, %13
%25 = load i32, i32* %3
ret i32 %25
}