#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hint;

/* Variables and functions */
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int initServer(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
               int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ serve(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct addrinfo *ailist, *aip;
  struct addrinfo hint;
  int sockfd, err, n;
  char *host;
  if (argc != 1) {
  }
  memset(&hint, 0, sizeof(hint));
  hint.ai_flags = AI_CANONNAME;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_canonname = NULL;
  hint.ai_addr = NULL;
  hint.ai_next = NULL;
  if ((err = getaddrinfo("localhost", "8080", &hint, &ailist)) != 0) {
    syslog(LOG_ERR, "ruptimed: getaddrinfo error: %s", gai_strerror(err));
    printf("getaddrinfo error\n");
    exit(1);
  }
  for (aip = ailist; aip != NULL; aip = aip->ai_next) {
    if ((sockfd = initServer(SOCK_STREAM, aip->ai_addr, aip->ai_addrlen, 10)) >=
        0) {
      serve(sockfd);
      exit(0);
    }
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11a5 <main+0x25>
jmp    11a5 <main+0x25>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe14(%rip),%rdi
lea    0xe17(%rip),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x50(%rbp)
cmp    $0x0,%eax
je     1247 <main+0xc7>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x50(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x64(%rbp),%edi
mov    %eax,%edx
lea    0xde3(%rip),%rsi
call   1080 <syslog@plt>
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ac <main+0x12c>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    $0xa,%ecx
call   1040 <initServer@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jl     1296 <main+0x116>
mov    -0x4c(%rbp),%edi
call   1070 <serve@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    129b <main+0x11b>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    124f <main+0xcf>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2e27(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe30(%rip),%rdi
lea    0xe33(%rip),%rsi
mov    %rsp,%rcx
mov    %r14,%rdx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
jne    121a <main+0x9a>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     1210 <main+0x90>
nop
mov    (%r15),%edi
mov    0x8(%rbx),%rsi
mov    (%rbx),%edx
mov    $0xa,%ecx
call   1040 <initServer@plt>
test   %eax,%eax
jns    1250 <main+0xd0>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
jne    11f0 <main+0x70>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2da7(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xdde(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1080 <syslog@plt>
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %eax,%edi
call   1070 <serve@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, %struct.addrinfo*, i32*, i32, i32 }
@AI_CANONNAME = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"8080\00"
@LOG_ERR = global i32 0
@.str.2 = [32 x i8] c"ruptimed: getaddrinfo error: %s\00"
@.str.3 = [19 x i8] c"getaddrinfo error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %2
br label %16
16: ; preds = %15, %2
%17 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 40)
%18 = load i32, i32* @AI_CANONNAME
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32* null, i32** %22
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 1
store i32* null, i32** %23
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store %struct.addrinfo* null, %struct.addrinfo** %24
%25 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %6)
store i32 %25, i32* %10
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %16
%28 = load i32, i32* @LOG_ERR
%29 = load i32, i32* %10
%30 = call i32 @gai_strerror(i32 %29)
%31 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %16
%35 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %35, %struct.addrinfo** %7
br label %36
36: ; preds = %54, %34
%37 = load %struct.addrinfo*, %struct.addrinfo** %7
%38 = icmp ne %struct.addrinfo* %37, null
br i1 %38, label %39, label %58
39: ; preds = %36
%40 = load i32, i32* @SOCK_STREAM
%41 = load %struct.addrinfo*, %struct.addrinfo** %7
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 1
%43 = load i32*, i32** %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %7
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @initServer(i32 %40, i32* %43, i32 %46, i32 10)
store i32 %47, i32* %9
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %39
%50 = load i32, i32* %9
%51 = call i32 @serve(i32 %50)
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %39
br label %54
54: ; preds = %53
%55 = load %struct.addrinfo*, %struct.addrinfo** %7
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 2
%57 = load %struct.addrinfo*, %struct.addrinfo** %56
store %struct.addrinfo* %57, %struct.addrinfo** %7
br label %36
58: ; preds = %36
%59 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, %struct.addrinfo*, i32*, i32, i32 }
@AI_CANONNAME = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"8080\00"
@LOG_ERR = global i32 0
@.str.2 = [32 x i8] c"ruptimed: getaddrinfo error: %s\00"
@str = [18 x i8] c"getaddrinfo error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 40)
%8 = load i32, i32* @AI_CANONNAME
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
%13 = bitcast i32** %12 to i8*
%14 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load %struct.addrinfo*, %struct.addrinfo** %3
%18 = icmp eq %struct.addrinfo* %17, null
br i1 %18, label %41, label %29
19: ; preds = %2
%20 = load i32, i32* @LOG_ERR
%21 = call i32 @gai_strerror(i32 %14)
%22 = call i32 @syslog(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %29
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 2
%27 = load %struct.addrinfo*, %struct.addrinfo** %26
%28 = icmp eq %struct.addrinfo* %27, null
br i1 %28, label %41, label %29
29: ; preds = %16, %25
%30 = phi %struct.addrinfo* [ %27, %25 ], [ %17, %16 ]
%31 = load i32, i32* @SOCK_STREAM
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 1
%33 = load i32*, i32** %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @initServer(i32 %31, i32* %33, i32 %35, i32 10)
%37 = icmp sgt i32 %36, -1
br i1 %37, label %38, label %25
38: ; preds = %29
%39 = call i32 @serve(i32 %36)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %25, %16
%42 = call i32 @exit(i32 1)
unreachable
}