#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ str_echo(int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int sockfd, n, newsockfd, childpid, servlen, fin;
  struct sockaddr_in serv_addr, cli_addr;
  socklen_t clilen;
  if (argc != 2) {
    usage();
    exit(1);
  }
  if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("servmulti : Probleme socket\n");
    exit(2);
  }
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = PF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(atoi(argv[1]));
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("servmulti : erreur bind\n");
    exit(1);
  }
  if (listen(sockfd, SOMAXCONN) < 0) {
    perror("servmulti : erreur listen\n");
    exit(1);
  }
  for (;;) {
    clilen = sizeof(cli_addr);
    newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
    if (newsockfd < 0) {
      perror("servmulti : erreur accept\n");
      exit(1);
    }
    if ((childpid = fork()) < 0) {
      perror("server: fork error\n");
      exit(1);
    } else if (childpid == 0) {
      close(sockfd);
      while (str_echo(newsockfd))
        ;
      exit(0);
    }
    close(newsockfd);
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
je     1211 <main+0x31>
mov    $0x0,%al
call   1090 <usage@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    124c <main+0x6c>
lea    0xdc3(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12c1 <main+0xe1>
lea    0xd6b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    12f2 <main+0x112>
lea    0xd53(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12f7 <main+0x117>
movl   $0xc,-0x4c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1331 <main+0x151>
lea    0xd2f(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    135a <main+0x17a>
lea    0xd21(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jne    138a <main+0x1aa>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <str_echo@plt>
cmp    $0x0,%rax
je     1383 <main+0x1a3>
jmp    136c <main+0x18c>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    138f <main+0x1af>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
jmp    12f7 <main+0x117>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    1225 <main+0x45>
mov    %rsi,%rbp
mov    0x2dcf(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
jns    1236 <main+0x56>
lea    0xdea(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
call   1090 <usage@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    129a <main+0xba>
lea    0xd88(%rip),%rdi
jmp    1330 <main+0x150>
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1080 <listen@plt>
test   %rax,%rax
jns    12b9 <main+0xd9>
lea    0xd7f(%rip),%rdi
jmp    1330 <main+0x150>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   10c0 <accept@plt>
test   %eax,%eax
js     1320 <main+0x140>
mov    %eax,%ebp
lea    0x18(%rsp),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
js     1329 <main+0x149>
je     133f <main+0x15f>
mov    %ebp,%edi
call   1070 <close@plt>
movl   $0xc,0x4(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10c0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12f0 <main+0x110>
lea    0xd2a(%rip),%rdi
jmp    1330 <main+0x150>
lea    0xd3c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %r14d,%edi
call   1070 <close@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <str_echo@plt>
test   %rax,%rax
jne    1350 <main+0x170>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [29 x i8] c"servmulti : Probleme socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [25 x i8] c"servmulti : erreur bind\0A\00"
@SOMAXCONN = global i32 0
@.str.2 = [27 x i8] c"servmulti : erreur listen\0A\00"
@.str.3 = [27 x i8] c"servmulti : erreur accept\0A\00"
@.str.4 = [20 x i8] c"server: fork error\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 i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (...) @usage()
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %20
%29 = bitcast %struct.sockaddr_in* %12 to i8*
%30 = call i32 @memset(i8* %29, i32 0, i32 12)
%31 = load i32, i32* @PF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = call i32 @htons(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %41, i32* %42
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%45 = call i64 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %28
%48 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %28
%51 = load i32, i32* %6
%52 = load i32, i32* @SOMAXCONN
%53 = call i64 @listen(i32 %51, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
br label %59
59: ; preds = %88, %58
store i32 12, i32* %14
%60 = load i32, i32* %6
%61 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%62 = call i32 @accept(i32 %60, %struct.sockaddr* %61, i32* %14)
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %59
%69 = call i32 (...) @fork()
store i32 %69, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %68
%75 = load i32, i32* %9
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %87
77: ; preds = %74
%78 = load i32, i32* %6
%79 = call i32 @close(i32 %78)
br label %80
80: ; preds = %84, %77
%81 = load i32, i32* %8
%82 = call i64 @str_echo(i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %80
br label %80
85: ; preds = %80
%86 = call i32 @exit(i32 0)
unreachable
87: ; preds = %74
br label %88
88: ; preds = %87
%89 = load i32, i32* %8
%90 = call i32 @close(i32 %89)
br label %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [29 x i8] c"servmulti : Probleme socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [25 x i8] c"servmulti : erreur bind\0A\00"
@SOMAXCONN = global i32 0
@.str.2 = [27 x i8] c"servmulti : erreur listen\0A\00"
@.str.3 = [27 x i8] c"servmulti : erreur accept\0A\00"
@.str.4 = [20 x i8] c"server: fork error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %13
%22 = call i32 @memset(i8* %6, i32 0, i32 12)
%23 = load i32, i32* @PF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i64 @bind(i32 %16, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %21
%37 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %21
%40 = load i32, i32* @SOMAXCONN
%41 = call i64 @listen(i32 %16, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %5
%45 = call i32 @accept(i32 %16, %struct.sockaddr* %44, i32* %5)
%46 = icmp slt i32 %45, 0
br i1 %46, label %50, label %53
47: ; preds = %39
%48 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %69, %43
%51 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %43, %69
%54 = phi i32 [ %71, %69 ], [ %45, %43 ]
%55 = call i32 (...) @fork()
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %53
%61 = icmp eq i32 %55, 0
br i1 %61, label %62, label %69
62: ; preds = %60
%63 = call i32 @close(i32 %16)
br label %64
64: ; preds = %64, %62
%65 = call i64 @str_echo(i32 %54)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %64
67: ; preds = %64
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %60
%70 = call i32 @close(i32 %54)
store i32 12, i32* %5
%71 = call i32 @accept(i32 %16, %struct.sockaddr* %44, i32* %5)
%72 = icmp slt i32 %71, 0
br i1 %72, label %50, label %53
}