#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_short;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ error_die(char *);
int getsockname(int, struct sockaddr *, void *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int startup(u_short *port) {
  int httpd = 0;
  struct sockaddr_in name;
  httpd = socket(PF_INET, SOCK_STREAM, 0);
  if (httpd == -1)
    error_die("socket");
  memset(&name, 0, sizeof(name));
  name.sin_family = AF_INET;
  name.sin_port = htons(*port);
  name.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
    error_die("bind");
  if (*port == 0) {
    int namelen = sizeof(name);
    if (getsockname(httpd, (struct sockaddr *)&name, (void *)&namelen) == -1)
      error_die("getsockname");
    *port = ntohs(name.sin_port);
  }
  if (listen(httpd, 5) < 0)
    error_die("listen");
  return (httpd);
}


x86 assembly (clang, -O0):
<startup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d5 <startup+0x45>
lea    0xe30(%rip),%rdi
call   1060 <error_die@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1237 <startup+0xa7>
lea    0xdd5(%rip),%rdi
call   1060 <error_die@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1280 <startup+0xf0>
movl   $0xc,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10a0 <getsockname@plt>
cmp    $0xffffffff,%eax
jne    1270 <startup+0xe0>
lea    0xda1(%rip),%rdi
call   1060 <error_die@plt>
mov    -0x18(%rbp),%edi
call   1080 <ntohs@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    12a3 <startup+0x113>
lea    0xd7a(%rip),%rdi
call   1060 <error_die@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startup>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11c8 <startup+0x38>
lea    0xe3d(%rip),%rdi
call   1060 <error_die@plt>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    (%r14),%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     1220 <startup+0x90>
cmpl   $0x0,(%r14)
jne    1265 <startup+0xd5>
jmp    1232 <startup+0xa2>
lea    0xde0(%rip),%rdi
call   1060 <error_die@plt>
cmpl   $0x0,(%r14)
jne    1265 <startup+0xd5>
movl   $0xc,0xc(%rsp)
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <getsockname@plt>
cmp    $0xffffffff,%eax
jne    125a <startup+0xca>
lea    0xdb7(%rip),%rdi
call   1060 <error_die@plt>
mov    (%rsp),%edi
call   1080 <ntohs@plt>
mov    %eax,(%r14)
mov    %ebx,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
test   %rax,%rax
jns    1282 <startup+0xf2>
lea    0xd9b(%rip),%rdi
call   1060 <error_die@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [12 x i8] c"getsockname\00"
@.str.3 = [7 x i8] c"listen\00"
define i32 @startup(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32*, i32** %2
%18 = load i32, i32* %17
%19 = call i32 @htons(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* %3
%26 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%27 = call i64 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %13
%30 = call i32 @error_die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %13
%32 = load i32*, i32** %2
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %31
store i32 12, i32* %5
%36 = load i32, i32* %3
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = bitcast i32* %5 to i8*
%39 = call i32 @getsockname(i32 %36, %struct.sockaddr* %37, i8* %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @error_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @ntohs(i32 %45)
%47 = load i32*, i32** %2
store i32 %46, i32* %47
br label %48
48: ; preds = %43, %31
%49 = load i32, i32* %3
%50 = call i64 @listen(i32 %49, i32 5)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [12 x i8] c"getsockname\00"
@.str.3 = [7 x i8] c"listen\00"
define i32 @startup(i32* nocapture %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* %0
%16 = call i32 @htons(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%22 = call i64 @bind(i32 %7, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 @error_die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
%27 = load i32, i32* %0
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%31 = call i32 @getsockname(i32 %7, %struct.sockaddr* %21, i8* %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @error_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %17
%37 = call i32 @ntohs(i32 %36)
store i32 %37, i32* %0
br label %38
38: ; preds = %35, %26
%39 = call i64 @listen(i32 %7, i32 5)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
ret i32 %7
}