#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 u_short;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ client_name;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ accept_request(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_die(char *);
int /*<<< orphan*/ printf(char *, int);
int startup(int *);
int main(void) {
  int server_sock = -1;
  u_short port = 80;
  int client_sock = -1;
  struct sockaddr_in client_name;
  socklen_t client_name_len = sizeof(client_name);
  server_sock = startup(&port);
  printf("httpd running on port %d\n", port);
  while (1) {
    client_sock =
        accept(server_sock, (struct sockaddr *)&client_name, &client_name_len);
    if (client_sock == -1)
      error_die("accept");
    accept_request(client_sock);
  }
  close(server_sock);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x50,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <startup@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11bf <main+0x6f>
lea    0xe60(%rip),%rdi
call   1050 <error_die@plt>
mov    -0x10(%rbp),%edi
call   1030 <accept_request@plt>
jmp    1196 <main+0x46>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x50,(%rsp)
movl   $0x4,0x4(%rsp)
mov    %rsp,%rdi
call   1060 <startup@plt>
mov    %eax,%ebx
mov    (%rsp),%esi
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xe85(%rip),%r12
jmp    11a7 <main+0x57>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <accept_request@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a0 <main+0x50>
mov    %r12,%rdi
call   1050 <error_die@plt>
jmp    11a0 <main+0x50>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"httpd running on port %d\0A\00"
@.str.1 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 80, i32* %3
store i32 -1, i32* %4
store i32 4, i32* %6
%7 = call i32 @startup(i32* %3)
store i32 %7, i32* %2
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %0, %18
%11 = load i32, i32* %2
%12 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%13 = call i32 @accept(i32 %11, %struct.sockaddr* %12, i32* %6)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %4
%20 = call i32 @accept_request(i32 %19)
br label %10
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"httpd running on port %d\0A\00"
@.str.1 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 80, i32* %1
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%7 = call i32 @startup(i32* %1)
%8 = load i32, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %11
11: ; preds = %16, %0
%12 = call i32 @accept(i32 %7, %struct.sockaddr* %10, i32* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = call i32 @accept_request(i32 %12)
br label %11
}