#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int creer_serveur(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fgets_or_exit(char *, int, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ initialiser_signaux();
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  int socket_serveur = creer_serveur(8080);
  initialiser_signaux();
  int statut;
  while (1) {
    int socket_client = accept(socket_serveur, NULL, NULL);
    if (socket_client == -1) {
      perror(" accept ");
    }
    int pid;
    if ((pid = fork()) == 0) {
      char *buf = malloc(255);
      FILE *f = fdopen(socket_client, "w+");
      fgets_or_exit(buf, 255, f);
      free(buf);
      fclose(f);
      return 1;
    }
    printf("connexion acceptée\n");
    if (waitpid(pid, &statut, WNOHANG) == -1)
      perror("erreur waitpid");
    close(socket_client);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1f90,%edi
call   1090 <creer_serveur@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <initialiser_signaux@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10e0 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    121b <main+0x4b>
lea    0xdea(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    127e <main+0xae>
mov    $0xff,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
lea    0xdc3(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xff,%esi
call   1030 <fgets_or_exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret
lea    0xd87(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d54(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   10c0 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0xe4>
lea    0xd72(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
jmp    11f3 <main+0x23>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1f90,%edi
call   1090 <creer_serveur@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <initialiser_signaux@plt>
lea    0xe26(%rip),%r15
mov    0x2dec(%rip),%r13
lea    0x4(%rsp),%r12
jmp    1217 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1261 <main+0x91>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     126f <main+0x9f>
mov    %eax,%r14d
mov    %r15,%rdi
call   1050 <puts@plt>
mov    0x0(%r13),%edx
mov    %r14d,%edi
mov    %r12,%rsi
call   10c0 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0x40>
lea    0xdb2(%rip),%rdi
call   10d0 <perror@plt>
jmp    1210 <main+0x40>
lea    0xd98(%rip),%rdi
call   10d0 <perror@plt>
jmp    1229 <main+0x59>
mov    $0xff,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xd86(%rip),%rsi
mov    %ebp,%edi
call   10b0 <fdopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1030 <fgets_or_exit@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c" accept \00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [21 x i8] c"connexion accept\C3\A9e\0A\00"
@WNOHANG = global i32 0
@.str.3 = [15 x i8] c"erreur waitpid\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32 @creer_serveur(i32 8080)
store i32 %8, i32* %2
%9 = call i32 (...) @initialiser_signaux()
br label %10
10: ; preds = %0, %39
%11 = load i32, i32* %2
%12 = call i32 @accept(i32 %11, i32* null, i32* null)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i32 (...) @fork()
store i32 %18, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = call i8* @malloc(i32 255)
store i8* %21, i8** %6
%22 = load i32, i32* %4
%23 = call i32* @fdopen(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i8*, i8** %6
%25 = load i32*, i32** %7
%26 = call i32 @fgets_or_exit(i8* %24, i32 255, i32* %25)
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
ret i32 1
31: ; preds = %17
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %5
%34 = load i32, i32* @WNOHANG
%35 = call i32 @waitpid(i32 %33, i32* %3, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
%40 = load i32, i32* %4
%41 = call i32 @close(i32 %40)
br label %10
}

LLVM IR (-O2):
@.str = [9 x i8] c" accept \00"
@.str.1 = [3 x i8] c"w+\00"
@WNOHANG = global i32 0
@.str.3 = [15 x i8] c"erreur waitpid\00"
@str = [20 x i8] c"connexion accept\C3\A9e\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @creer_serveur(i32 8080)
%3 = tail call i32 (...) @initialiser_signaux()
%4 = bitcast i32* %1 to i8*
br label %5
5: ; preds = %20, %0
%6 = call i32 @accept(i32 %2, i32* null, i32* null)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @WNOHANG
%16 = call i32 @waitpid(i32 %11, i32* %1, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %13, %18
%21 = call i32 @close(i32 %6)
br label %5
22: ; preds = %10
%23 = call dereferenceable_or_null(255) i8* @malloc(i32 255)
%24 = call i32* @fdopen(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @fgets_or_exit(i8* %23, i32 255, i32* %24)
%26 = call i32 @free(i8* %23)
%27 = call i32 @fclose(i32* %24)
ret i32 1
}