#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*/ tmpisa;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addrtype;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ handle_incoming(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int http_initiate_webserver(int portnumber) {
  char localhostname[256 + 1];
  struct sockaddr_in sa, tmpisa;
  int incoming_socket;
  int t;
  struct hostent *hp;
  int i;
  puts("Upaccho web server version 0.0.1\n"
       "copyright 2001,2005 Junichi Uekawa\n");
  gethostname(localhostname, 256);
  if ((hp = gethostbyname(localhostname)) == NULL) {
    fprintf(stderr, "cannot get localhost info\n");
    exit(1);
  }
  if ((incoming_socket = socket(hp->h_addrtype, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  sa.sin_port = htons(portnumber);
  sa.sin_addr.s_addr = htonl(INADDR_ANY);
  sa.sin_family = hp->h_addrtype;
  if (bind(incoming_socket, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
    perror("bind");
    exit(1);
  }
  listen(incoming_socket, 256);
  while (1) {
    i = sizeof(tmpisa);
    if ((t = accept(incoming_socket, (struct sockaddr *)&tmpisa, &i)) == -1) {
      perror("accept");
      exit(1);
    }
    handle_incoming(t);
    close(t);
  }
}


x86 assembly (clang, -O0):
<http_initiate_webserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <gethostname@plt>
lea    -0x110(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x140(%rbp)
cmp    $0x0,%rax
jne    1247 <http_initiate_webserver+0x67>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x140(%rbp),%rax
mov    (%rax),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x134(%rbp)
cmp    $0xffffffff,%eax
jne    1285 <http_initiate_webserver+0xa5>
lea    0xdea(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x118(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x11c(%rbp)
mov    -0x140(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
mov    -0x134(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12ed <http_initiate_webserver+0x10d>
lea    0xd89(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x134(%rbp),%edi
mov    $0x100,%esi
call   1090 <listen@plt>
movl   $0xc,-0x144(%rbp)
mov    -0x134(%rbp),%edi
lea    -0x130(%rbp),%rsi
lea    -0x144(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x138(%rbp)
cmp    $0xffffffff,%eax
jne    1345 <http_initiate_webserver+0x165>
lea    0xd36(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x138(%rbp),%edi
call   10f0 <handle_incoming@plt>
mov    -0x138(%rbp),%edi
call   1060 <close@plt>
jmp    12fd <http_initiate_webserver+0x11d>

x86 assembly (clang, -O2):
<http_initiate_webserver>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %edi,%r14d
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10d0 <gethostname@plt>
mov    %rbx,%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
jne    123a <http_initiate_webserver+0x5a>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rax,%rbp
mov    (%rax),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    1260 <http_initiate_webserver+0x80>
lea    0xe05(%rip),%rdi
jmp    1312 <http_initiate_webserver+0x132>
mov    %eax,%r15d
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    12a8 <http_initiate_webserver+0xc8>
lea    0xdc1(%rip),%rdi
jmp    1312 <http_initiate_webserver+0x132>
mov    %r15d,%edi
mov    $0x100,%esi
call   1090 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
je     130b <http_initiate_webserver+0x12b>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%rbx
mov    %ebp,%edi
call   10f0 <handle_incoming@plt>
mov    %ebp,%edi
call   1060 <close@plt>
movl   $0xc,0xc(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    12e0 <http_initiate_webserver+0x100>
lea    0xd5a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [69 x i8] c"Upaccho web server version 0.0.1\0Acopyright 2001,2005 Junichi Uekawa\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"cannot get localhost info\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
define i32 @http_initiate_webserver(i32 %0) {
%2 = alloca i32
%3 = alloca [257 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.hostent*
%9 = alloca i32
store i32 %0, i32* %2
%10 = call i32 @puts(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%12 = call i32 @gethostname(i8* %11, i32 256)
%13 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%14 = call %struct.hostent* @gethostbyname(i8* %13)
store %struct.hostent* %14, %struct.hostent** %8
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
%21 = load %struct.hostent*, %struct.hostent** %8
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32, i32* %2
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load %struct.hostent*, %struct.hostent** %8
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i64 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %30
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %30
%50 = load i32, i32* %6
%51 = call i32 @listen(i32 %50, i32 256)
br label %52
52: ; preds = %49, %60
store i32 12, i32* %9
%53 = load i32, i32* %6
%54 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%55 = call i32 @accept(i32 %53, %struct.sockaddr* %54, i32* %9)
store i32 %55, i32* %7
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
%61 = load i32, i32* %7
%62 = call i32 @handle_incoming(i32 %61)
%63 = load i32, i32* %7
%64 = call i32 @close(i32 %63)
br label %52
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [69 x i8] c"Upaccho web server version 0.0.1\0Acopyright 2001,2005 Junichi Uekawa\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"cannot get localhost info\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
define i32 @http_initiate_webserver(i32 %0) {
%2 = alloca [257 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @gethostname(i8* %6, i32 256)
%12 = call %struct.hostent* @gethostbyname(i8* %6)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = call i32 @htons(i32 %0)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* @INADDR_ANY
%31 = call i32 @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %19
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i64 @bind(i32 %22, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %27
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %27
%42 = call i32 @listen(i32 %22, i32 256)
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %5
%44 = call i32 @accept(i32 %22, %struct.sockaddr* %43, i32* %5)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %49, %41
%47 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %41, %49
%50 = phi i32 [ %53, %49 ], [ %44, %41 ]
%51 = call i32 @handle_incoming(i32 %50)
%52 = call i32 @close(i32 %50)
store i32 12, i32* %5
%53 = call i32 @accept(i32 %22, %struct.sockaddr* %43, i32* %5)
%54 = icmp eq i32 %53, -1
br i1 %54, label %46, label %49
}