#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 */
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct linger {
  int l_onoff;
  int l_linger;
};
typedef int /*<<< orphan*/ ling;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
int /*<<< orphan*/ abort();
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct linger *,
               int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int startup(uint16_t port) {
  static const char *host = "127.0.0.1";
  int fd = socket(AF_INET, SOCK_STREAM, 0);
  {
    if (fd == -1) {
      perror("socket");
      abort();
    }
  };
  ;
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  int success = inet_pton(AF_INET, host, &addr.sin_addr);
  {
    if (success <= 0) {
      perror("inet_pton");
      abort();
    }
  };
  ;
  struct linger ling = {.l_onoff = 1, .l_linger = 10};
  int err = setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
  {
    if (err != 0) {
      perror("setsockopt");
      abort();
    }
  };
  ;
  err = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
  {
    if (err != 0) {
      perror("connect");
      abort();
    }
  };
  ;
  return fd;
}


x86 assembly (clang, -O0):
<startup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b4 <startup+0x44>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x2e7d(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1204 <startup+0x94>
lea    0xe19(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0xe25(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1253 <startup+0xe3>
lea    0xdd4(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1284 <startup+0x114>
lea    0xdae(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startup>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
mov    0x2e5f(%rip),%r14
mov    (%r14),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     1220 <startup+0xb0>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r14),%edi
lea    0xe45(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <inet_pton@plt>
test   %eax,%eax
jle    1229 <startup+0xb9>
movabs $0xa00000001,%rax
mov    %rax,0x18(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
test   %eax,%eax
jne    1232 <startup+0xc2>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <connect@plt>
test   %eax,%eax
jne    123b <startup+0xcb>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde3(%rip),%rdi
jmp    1242 <startup+0xd2>
lea    0xde1(%rip),%rdi
jmp    1242 <startup+0xd2>
lea    0xde2(%rip),%rdi
jmp    1242 <startup+0xd2>
lea    0xde4(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.linger = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@startup.host = internal global i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0)
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@__const.startup.ling = %struct.linger { i32 1, i32 10 }
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@.str.4 = [8 x i8] c"connect\00"
define i32 @startup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca %struct.linger
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* %2
%20 = call i32 @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = load i8*, i8** @startup.host
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%25 = call i32 @inet_pton(i32 %22, i8* %23, i32* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %16
%32 = bitcast %struct.linger* %6 to i8*
%33 = load i32, i32* %3
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_LINGER
%36 = call i32 @setsockopt(i32 %33, i32 %34, i32 %35, %struct.linger* %6, i32 8)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %31
%43 = load i32, i32* %3
%44 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%45 = call i32 @connect(i32 %43, %struct.sockaddr* %44, i32 12)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 (...) @abort()
unreachable
51: ; preds = %42
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.linger = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@.str.4 = [8 x i8] c"connect\00"
define i32 @startup(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.linger*
%5 = load i32, i32* @AF_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 %12
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %1
%13 = bitcast %struct.sockaddr_in* %2 to i8*
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 %0)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%20 = call i32 @inet_pton(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %12
%26 = bitcast i64* %3 to i8*
store i64 42949672961, i64* %3
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_LINGER
%29 = call i32 @setsockopt(i32 %7, i32 %27, i32 %28, %struct.linger* %4, i32 8)
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %25
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = call i32 @connect(i32 %7, %struct.sockaddr* %35, i32 12)
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %34
ret i32 %7
}