#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SHUT_RDWR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int htons(int /*<<< orphan*/);
int http_session(int *, struct sockaddr_in *);
char *inet_ntoa(int /*<<< orphan*/);
int init_socket(int *, struct sockaddr_in *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, ...);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int listen_fd;
  int connect_fd;
  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  bzero(&server_addr, sizeof(struct sockaddr_in));
  bzero(&client_addr, sizeof(struct sockaddr_in));
  if (init_socket(&listen_fd, &server_addr) == -1) {
    perror("init_socket() error. in webserver.c");
    exit(EXIT_FAILURE);
  }
  socklen_t addrlen = sizeof(struct sockaddr_in);
  pid_t pid;
  while (1) {
    if ((connect_fd = accept(listen_fd, (struct sockaddr *)&client_addr,
                             &addrlen)) == -1) {
      perror("accept() error. in webserver.c");
      continue;
    }
    if ((pid = fork()) > 0) {
      close(connect_fd);
      continue;
    } else if (pid == 0) {
      close(listen_fd);
      printf("pid %d process http session from %s : %d\n", getpid(),
             inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));
      if (http_session(&connect_fd, &client_addr) == -1) {
        perror("http_session() error. in webserver.c");
        shutdown(connect_fd, SHUT_RDWR);
        printf("pid %d loss connection to %s\n", getpid(),
               inet_ntoa(client_addr.sin_addr));
        exit(EXIT_FAILURE);
      }
      printf("pid %d close connection to %s\n", getpid(),
             inet_ntoa(client_addr.sin_addr));
      shutdown(connect_fd, SHUT_RDWR);
      exit(EXIT_SUCCESS);
    } else {
      perror("fork() error. in webserver.c");
      exit(EXIT_FAILURE);
    }
  }
  shutdown(listen_fd, SHUT_RDWR);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
lea    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
lea    -0x14(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <init_socket@plt>
cmp    $0xffffffff,%eax
jne    1232 <main+0x62>
lea    0xde1(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1266 <main+0x96>
lea    0xdc8(%rip),%rdi
call   10a0 <perror@plt>
jmp    1239 <main+0x69>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jle    1288 <main+0xb8>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    1239 <main+0x69>
cmpq   $0x0,-0x38(%rbp)
jne    137c <main+0x1ac>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <htons@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10e0 <http_session@plt>
cmp    $0xffffffff,%eax
jne    1337 <main+0x167>
lea    0xd80(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x48(%rbp),%esi
mov    %rax,%rdx
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2c89(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xd4c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
lea    0x18(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <init_socket@plt>
cmp    $0xffffffff,%eax
jne    1219 <main+0x49>
lea    0xdec(%rip),%rdi
jmp    1311 <main+0x141>
movl   $0x8,0x1c(%rsp)
lea    0x10(%rsp),%r14
lea    0x1c(%rsp),%rbx
lea    0xdf2(%rip),%r15
jmp    1240 <main+0x70>
mov    %r15,%rdi
call   10a0 <perror@plt>
nopl   0x0(%rax)
mov    0x18(%rsp),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <accept@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1234 <main+0x64>
mov    %eax,%ebp
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
jle    126f <main+0x9f>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    1240 <main+0x70>
jne    130a <main+0x13a>
mov    0x18(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x14(%rsp),%edi
call   1060 <htons@plt>
lea    0xda0(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10e0 <http_session@plt>
cmp    $0xffffffff,%eax
jne    1324 <main+0x154>
lea    0xda1(%rip),%rdi
call   10a0 <perror@plt>
mov    0xc(%rsp),%edi
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xd96(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1316 <main+0x146>
lea    0xdbe(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xd73(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%edi
mov    0x2c9c(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"init_socket() error. in webserver.c\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"accept() error. in webserver.c\00"
@.str.2 = [42 x i8] c"pid %d process http session from %s : %d\0A\00"
@.str.3 = [37 x i8] c"http_session() error. in webserver.c\00"
@SHUT_RDWR = global i32 0
@.str.4 = [30 x i8] c"pid %d loss connection to %s\0A\00"
@.str.5 = [31 x i8] c"pid %d close connection to %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [29 x i8] c"fork() error. in webserver.c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @bzero(%struct.sockaddr_in* %8, i32 8)
%13 = call i32 @bzero(%struct.sockaddr_in* %9, i32 8)
%14 = call i32 @init_socket(i32* %6, %struct.sockaddr_in* %8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
store i32 8, i32* %10
br label %21
21: ; preds = %20, %26, %31
%22 = load i32, i32* %6
%23 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%24 = call i32 @accept(i32 %22, %struct.sockaddr* %23, i32* %10)
store i32 %24, i32* %7
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %21
28: ; preds = %21
%29 = call i64 (...) @fork()
store i64 %29, i64* %11
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
br label %21
34: ; preds = %28
%35 = load i64, i64* %11
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %73
37: ; preds = %34
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = call i32 (...) @getpid()
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i8* @inet_ntoa(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 @htons(i32 %45)
%47 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %40, i8* %43, i32 %46)
%48 = call i32 @http_session(i32* %7, %struct.sockaddr_in* %9)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %62
50: ; preds = %37
%51 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %7
%53 = load i32, i32* @SHUT_RDWR
%54 = call i32 @shutdown(i32 %52, i32 %53)
%55 = call i32 (...) @getpid()
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i8* @inet_ntoa(i32 %57)
%59 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %55, i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %37
%63 = call i32 (...) @getpid()
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i8* @inet_ntoa(i32 %65)
%67 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %63, i8* %66)
%68 = load i32, i32* %7
%69 = load i32, i32* @SHUT_RDWR
%70 = call i32 @shutdown(i32 %68, i32 %69)
%71 = load i32, i32* @EXIT_SUCCESS
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %34
%74 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"init_socket() error. in webserver.c\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [31 x i8] c"accept() error. in webserver.c\00"
@.str.2 = [42 x i8] c"pid %d process http session from %s : %d\0A\00"
@.str.3 = [37 x i8] c"http_session() error. in webserver.c\00"
@SHUT_RDWR = global i32 0
@.str.4 = [30 x i8] c"pid %d loss connection to %s\0A\00"
@.str.5 = [31 x i8] c"pid %d close connection to %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [29 x i8] c"fork() error. in webserver.c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast %struct.sockaddr_in* %6 to i8*
%12 = call i32 @bzero(%struct.sockaddr_in* %5, i32 8)
%13 = call i32 @bzero(%struct.sockaddr_in* %6, i32 8)
%14 = call i32 @init_socket(i32* %3, %struct.sockaddr_in* %5)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = bitcast i32* %7 to i8*
store i32 8, i32* %7
%22 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %23
23: ; preds = %29, %20
%24 = load i32, i32* %3
%25 = call i32 @accept(i32 %24, %struct.sockaddr* %22, i32* %7)
store i32 %25, i32* %4
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %33
br label %23
30: ; preds = %23
%31 = call i64 (...) @fork()
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @close(i32 %25)
br label %29
35: ; preds = %30
%36 = icmp eq i64 %31, 0
br i1 %36, label %37, label %71
37: ; preds = %35
%38 = load i32, i32* %3
%39 = call i32 @close(i32 %38)
%40 = call i32 (...) @getpid()
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i8* @inet_ntoa(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 @htons(i32 %45)
%47 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %40, i8* %43, i32 %46)
%48 = call i32 @http_session(i32* %4, %struct.sockaddr_in* %6)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %61
50: ; preds = %37
%51 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %4
%53 = load i32, i32* @SHUT_RDWR
%54 = call i32 @shutdown(i32 %52, i32 %53)
%55 = call i32 (...) @getpid()
%56 = load i32, i32* %41
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %55, i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %37
%62 = call i32 (...) @getpid()
%63 = load i32, i32* %41
%64 = call i8* @inet_ntoa(i32 %63)
%65 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %62, i8* %64)
%66 = load i32, i32* %4
%67 = load i32, i32* @SHUT_RDWR
%68 = call i32 @shutdown(i32 %66, i32 %67)
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %35
%72 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
}