#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 /*<<< 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 = 0;
  int client_sock = -1;
  struct sockaddr_in client_name;
  int 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");
      break;
    }
    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   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <startup@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11d4 <main+0x74>
lea    0xe50(%rip),%rdi
call   1050 <error_die@plt>
jmp    11e1 <main+0x81>
mov    -0x10(%rbp),%edi
call   1030 <accept_request@plt>
jmp    11a6 <main+0x46>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x4(%rsp)
movl   $0x4,(%rsp)
lea    0x4(%rsp),%rdi
call   1070 <startup@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x69>
lea    0x8(%rsp),%r14
mov    %rsp,%r15
mov    %eax,%edi
call   1030 <accept_request@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x50>
lea    0xe4a(%rip),%rdi
call   1050 <error_die@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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 0, 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 %21
18: ; preds = %10
%19 = load i32, i32* %4
%20 = call i32 @accept_request(i32 %19)
br label %10
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
ret i32 0
}

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 0, 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*
%11 = call i32 @accept(i32 %7, %struct.sockaddr* %10, i32* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %16, %0
%14 = call i32 @error_die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @close(i32 %7)
ret i32 0
16: ; preds = %0, %16
%17 = phi i32 [ %19, %16 ], [ %11, %0 ]
%18 = call i32 @accept_request(i32 %17)
%19 = call i32 @accept(i32 %7, %struct.sockaddr* %10, i32* %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %13, label %16
}