#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 {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ echo_lines(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
void take_connections_forever(int ssock) {
  for (;;) {
    struct sockaddr addr;
    socklen_t addr_size = sizeof(addr);
    int csock;
    csock = accept(ssock, &addr, &addr_size);
    if (csock == -1) {
      perror("accept");
    } else if (fork() == 0) {
      close(ssock);
      echo_lines(csock);
    } else {
      close(csock);
    }
  }
}


x86 assembly (clang, -O0):
<take_connections_forever>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1190 <take_connections_forever+0x40>
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
jmp    11c3 <take_connections_forever+0x73>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11b6 <take_connections_forever+0x66>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1030 <echo_lines@plt>
jmp    11be <take_connections_forever+0x6e>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
jmp    11c3 <take_connections_forever+0x73>
jmp    115b <take_connections_forever+0xb>

x86 assembly (clang, -O2):
<take_connections_forever>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xe91(%rip),%r12
jmp    1188 <take_connections_forever+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1050 <perror@plt>
movl   $0x4,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <accept@plt>
cmp    $0xffffffff,%eax
je     1180 <take_connections_forever+0x30>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11c0 <take_connections_forever+0x70>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1030 <echo_lines@plt>
jmp    1188 <take_connections_forever+0x38>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1188 <take_connections_forever+0x38>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
define void @take_connections_forever(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %25, %1
store i32 4, i32* %4
%7 = load i32, i32* %2
%8 = call i32 @accept(i32 %7, %struct.sockaddr* %3, i32* %4)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %25
13: ; preds = %6
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @echo_lines(i32 %19)
br label %24
21: ; preds = %13
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
br label %24
24: ; preds = %21, %16
br label %25
25: ; preds = %24, %11
br label %6
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
define void @take_connections_forever(i32 %0) {
%2 = alloca %struct.sockaddr
%3 = alloca i32
%4 = bitcast %struct.sockaddr* %2 to i8*
%5 = bitcast i32* %3 to i8*
br label %6
6: ; preds = %19, %1
store i32 4, i32* %3
%7 = call i32 @accept(i32 %0, %struct.sockaddr* %2, i32* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
11: ; preds = %6
%12 = call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @close(i32 %0)
%16 = call i32 @echo_lines(i32 %7)
br label %19
17: ; preds = %11
%18 = call i32 @close(i32 %7)
br label %19
19: ; preds = %14, %17, %9
br label %6
}