#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 dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ ProcessRequest(int);
int /*<<< orphan*/ SSTL_MasterSocketInit(int *, int *);
int /*<<< orphan*/ SyslogErrExit(char *, scalar_t__, int);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
main(int argc, char **argv) {
  int port;
  int master_sock;
  int slave_sock;
  int slave_sock_addr_len;
  struct sockaddr_in acc_s_server;
  SSTL_MasterSocketInit(&port, &master_sock);
  slave_sock_addr_len = sizeof(struct sockaddr);
  while (1) {
    slave_sock = accept(master_sock, (struct sockaddr *)&acc_s_server,
                        &slave_sock_addr_len);
    if (slave_sock < 0) {
      if (errno == EINTR)
        continue;
      SyslogErrExit("accept failed - errno %d\n", errno, -1);
    }
    switch (fork()) {
    case 0:
      (void)close(master_sock);
      exit(ProcessRequest(slave_sock));
      break;
    case -1:
      SyslogErrExit("fork failed - errno %d\n", errno, -1);
      break;
    default:
      (void)close(slave_sock);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <SSTL_MasterSocketInit@plt>
movl   $0x4,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f1 <main+0x81>
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
jne    11d6 <main+0x66>
jmp    119a <main+0x2a>
mov    0x2e03(%rip),%rax
mov    (%rax),%rsi
lea    0xe19(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <SyslogErrExit@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     1232 <main+0xc2>
jmp    120b <main+0x9b>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jne    1252 <main+0xe2>
jmp    121b <main+0xab>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <ProcessRequest@plt>
mov    %eax,%edi
call   1070 <exit@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%rsi
lea    0xdd7(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <SyslogErrExit@plt>
jmp    125a <main+0xea>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
jmp    119a <main+0x2a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <SSTL_MasterSocketInit@plt>
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%rbx
mov    0x2e3a(%rip),%r13
mov    0x2e2b(%rip),%r15
lea    0xe66(%rip),%r12
jmp    11d1 <main+0x61>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%rsi
mov    %r12,%rdi
mov    $0xffffffff,%edx
call   1040 <SyslogErrExit@plt>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1200 <main+0x90>
mov    0x0(%r13),%rsi
cmp    (%r15),%rsi
je     11d1 <main+0x61>
lea    0xe0a(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <SyslogErrExit@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11c0 <main+0x50>
test   %eax,%eax
je     1219 <main+0xa9>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    11d1 <main+0x61>
mov    0x8(%rsp),%edi
call   1030 <close@plt>
mov    %ebp,%edi
call   1050 <ProcessRequest@plt>
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [26 x i8] c"accept failed - errno %d\0A\00"
@.str.1 = [24 x i8] c"fork failed - errno %d\0A\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 i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @SSTL_MasterSocketInit(i32* %6, i32* %7)
store i32 4, i32* %9
br label %12
12: ; preds = %2, %22, %40
%13 = load i32, i32* %7
%14 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%15 = call i32 @accept(i32 %13, %struct.sockaddr* %14, i32* %9)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %12
23: ; preds = %18
%24 = load i64, i64* @errno
%25 = call i32 @SyslogErrExit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %24, i32 -1)
br label %26
26: ; preds = %23, %12
%27 = call i32 (...) @fork()
switch i32 %27, label %37 [
i32 0, label %28
i32 -1, label %34
]
28: ; preds = %26
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %8
%32 = call i32 @ProcessRequest(i32 %31)
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = load i64, i64* @errno
%36 = call i32 @SyslogErrExit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %35, i32 -1)
br label %40
37: ; preds = %26
%38 = load i32, i32* %8
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %37, %34
br label %12
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [26 x i8] c"accept failed - errno %d\0A\00"
@.str.1 = [24 x i8] c"fork failed - errno %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = call i32 @SSTL_MasterSocketInit(i32* %3, i32* %4)
store i32 4, i32* %5
%12 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %13
13: ; preds = %33, %2
%14 = load i32, i32* %4
%15 = call i32 @accept(i32 %14, %struct.sockaddr* %12, i32* %5)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = call i32 @SyslogErrExit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %18, i32 -1)
br label %23
23: ; preds = %21, %13
%24 = call i32 (...) @fork()
switch i32 %24, label %34 [
i32 0, label %25
i32 -1, label %30
]
25: ; preds = %23
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
%28 = call i32 @ProcessRequest(i32 %15)
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
%31 = load i64, i64* @errno
%32 = call i32 @SyslogErrExit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %31, i32 -1)
br label %33
33: ; preds = %30, %34, %17
br label %13
34: ; preds = %23
%35 = call i32 @close(i32 %15)
br label %33
}