#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;
};
typedef int socklen_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ echo(int);
int /*<<< orphan*/ perror(char *);
int setup(int, char **);
int main(int argc, char **argv) {
  int msock, sock;
  struct sockaddr_in remote;
  socklen_t socksize = sizeof(struct sockaddr);
  if ((msock = setup(argc, argv)) == -1) {
    return EXIT_FAILURE;
  }
  for (;;) {
    sock = accept(msock, (struct sockaddr *)&remote, &socksize);
    if (sock == -1) {
      perror("accept");
      continue;
    }
    echo(sock);
    close(sock);
  }
  close(msock);
  return EXIT_SUCCESS;
}


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)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <setup@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1194 <main+0x44>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    1199 <main+0x49>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c7 <main+0x77>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
jmp    1199 <main+0x49>
mov    -0x18(%rbp),%edi
call   1030 <echo@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    1199 <main+0x49>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
call   1070 <setup@plt>
cmp    $0xffffffff,%eax
je     11bc <main+0x6c>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xe7f(%rip),%r12
jmp    11a0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <echo@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <accept@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x40>
mov    %r12,%rdi
call   1050 <perror@plt>
jmp    11a0 <main+0x50>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [7 x i8] c"accept\00"
@EXIT_SUCCESS = global i32 0
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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %9
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @setup(i32 %10, i8** %11)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
ret i32 %15
16: ; preds = %2
br label %17
17: ; preds = %25, %23, %16
%18 = load i32, i32* %6
%19 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%20 = call i32 @accept(i32 %18, %struct.sockaddr* %19, i32* %9)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
25: ; preds = %17
%26 = load i32, i32* %7
%27 = call i32 @echo(i32 %26)
%28 = load i32, i32* %7
%29 = call i32 @close(i32 %28)
br label %17
}

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