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

/* Variables and functions */
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ afficherBienvenue(int);
int /*<<< orphan*/ afficherErreur400(int);
int /*<<< orphan*/ close(int);
int creer_serveur(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ initialiser_signaux();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strncmp(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ traitement_signal(int);
int verif(char *);
int main(void) {
  int socket_serveur = creer_serveur(8000);
  int socket_client;
  char words[50];
  FILE *fp;
  while (1) {
    socket_client = accept(socket_serveur, NULL, NULL);
    traitement_signal(socket_client);
    int pid = fork();
    if (socket_client == -1) {
      perror("accept");
    }
    initialiser_signaux();
    sleep(1);
    if (pid == 0) {
      while (1) {
        if ((fp = fdopen(socket_client, "w+")) == NULL) {
          fprintf(stdout, "Problème socket client.\n");
          exit(1);
        }
        puts("<pawnee>\n");
        while (fgets(words, 50, fp) != NULL && words[0] != '\0') {
          int verifier = verif(words);
          while (strncmp("\r\n", fgets(words, sizeof(words), fp), 2) != 0) {
          }
          if (verifier == -1) {
            afficherErreur400(socket_client);
          } else {
            afficherBienvenue(socket_client);
          }
        }
        rewind(fp);
        while (fscanf(fp, "%s", words) > 0) {
          puts(words);
        }
        if (fclose(fp) != 0) {
          fprintf(stderr, "Erreur fermeture fichier\n");
        }
      }
    }
    close(socket_client);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1f40,%edi
call   10c0 <creer_serveur@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1120 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <traitement_signal@plt>
mov    $0x0,%al
call   1160 <fork@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1296 <main+0x56>
lea    0xd6f(%rip),%rdi
call   1110 <perror@plt>
mov    $0x0,%al
call   1050 <initialiser_signaux@plt>
mov    $0x1,%edi
call   1140 <sleep@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    1406 <main+0x1c6>
jmp    12b6 <main+0x76>
mov    -0xc(%rbp),%edi
lea    0xd47(%rip),%rsi
call   1100 <fdopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    12f2 <main+0xb2>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xd2b(%rip),%rdi
call   1040 <puts@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x32,%esi
call   10e0 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x51(%rbp)
je     132f <main+0xef>
movsbl -0x40(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    133f <main+0xff>
jmp    13a4 <main+0x164>
lea    -0x40(%rbp),%rdi
call   10d0 <verif@plt>
mov    %eax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x32,%esi
call   10e0 <fgets@plt>
mov    %rax,%rsi
lea    0xcc7(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1380 <main+0x140>
jmp    134b <main+0x10b>
cmpl   $0xffffffff,-0x50(%rbp)
jne    1397 <main+0x157>
mov    -0xc(%rbp),%edi
call   1150 <afficherErreur400@plt>
jmp    139f <main+0x15f>
mov    -0xc(%rbp),%edi
call   1080 <afficherBienvenue@plt>
jmp    12fe <main+0xbe>
mov    -0x48(%rbp),%rdi
call   1090 <rewind@plt>
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xc75(%rip),%rsi
call   10a0 <fscanf@plt>
cmp    $0x0,%rax
jle    13d9 <main+0x199>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
jmp    13ad <main+0x16d>
mov    -0x48(%rbp),%rdi
call   1070 <fclose@plt>
cmp    $0x0,%rax
je     1401 <main+0x1c1>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
lea    0xc38(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    12b6 <main+0x76>
mov    -0xc(%rbp),%edi
call   10b0 <close@plt>
jmp    125c <main+0x1c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x1f40,%edi
call   10c0 <creer_serveur@plt>
mov    %eax,%ebx
lea    0xd9f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1120 <accept@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <traitement_signal@plt>
xor    %eax,%eax
call   1160 <fork@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%r15d
je     12b3 <main+0x73>
xor    %eax,%eax
call   1050 <initialiser_signaux@plt>
mov    $0x1,%edi
call   1140 <sleep@plt>
test   %ebp,%ebp
je     12bd <main+0x7d>
mov    %r15d,%edi
call   10b0 <close@plt>
jmp    1270 <main+0x30>
mov    %r14,%rdi
call   1110 <perror@plt>
jmp    1294 <main+0x54>
lea    0xd43(%rip),%rsi
mov    %r15d,%edi
call   1100 <fdopen@plt>
test   %rax,%rax
jne    12f0 <main+0xb0>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xd31(%rip),%rbp
lea    0xd2d(%rip),%r12
jmp    1327 <main+0xe7>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
lea    0xced(%rip),%rsi
call   1100 <fdopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     12d1 <main+0x91>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
jmp    1345 <main+0x105>
cs nopw 0x0(%rax,%rax,1)
nop
call   1080 <afficherBienvenue@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   10e0 <fgets@plt>
test   %rax,%rax
je     13b0 <main+0x170>
cmpb   $0x0,(%rsp)
je     13b0 <main+0x170>
mov    %rbx,%rdi
call   10d0 <verif@plt>
mov    %eax,%r13d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   10e0 <fgets@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1370 <main+0x130>
mov    %r15d,%edi
cmp    $0xffffffff,%r13d
jne    1340 <main+0x100>
call   1150 <afficherErreur400@plt>
jmp    1345 <main+0x105>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1090 <rewind@plt>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <fscanf@plt>
test   %rax,%rax
jle    13e0 <main+0x1a0>
mov    %rbx,%rdi
call   1040 <puts@plt>
jmp    13c0 <main+0x180>
nopl   (%rax)
mov    %r14,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
je     1310 <main+0xd0>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    1310 <main+0xd0>

LLVM IR (-O0):
@.str = [7 x i8] c"accept\00"
@.str.1 = [3 x i8] c"w+\00"
@stdout = global i32 0
@.str.2 = [26 x i8] c"Probl\C3\A8me socket client.\0A\00"
@.str.3 = [10 x i8] c"<pawnee>\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"Erreur fermeture fichier\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @creer_serveur(i32 8000)
store i32 %8, i32* %2
br label %9
9: ; preds = %0, %86
%10 = load i32, i32* %2
%11 = call i32 @accept(i32 %10, i32* null, i32* null)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @traitement_signal(i32 %12)
%14 = call i32 (...) @fork()
store i32 %14, i32* %6
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %9
%20 = call i32 (...) @initialiser_signaux()
%21 = call i32 @sleep(i32 1)
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %86
24: ; preds = %19
br label %25
25: ; preds = %24, %85
%26 = load i32, i32* %3
%27 = call i32* @fdopen(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %5
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @stdout
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %66, %33
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%37 = load i32*, i32** %5
%38 = call i32* @fgets(i8* %36, i32 50, i32* %37)
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br label %45
45: ; preds = %40, %35
%46 = phi i1 [ false, %35 ], [ %44, %40 ]
br i1 %46, label %47, label %67
47: ; preds = %45
%48 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%49 = call i32 @verif(i8* %48)
store i32 %49, i32* %7
br label %50
50: ; preds = %56, %47
%51 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%52 = load i32*, i32** %5
%53 = call i32* @fgets(i8* %51, i32 50, i32* %52)
%54 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %53, i32 2)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
br label %50
57: ; preds = %50
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32, i32* %3
%62 = call i32 @afficherErreur400(i32 %61)
br label %66
63: ; preds = %57
%64 = load i32, i32* %3
%65 = call i32 @afficherBienvenue(i32 %64)
br label %66
66: ; preds = %63, %60
br label %35
67: ; preds = %45
%68 = load i32*, i32** %5
%69 = call i32 @rewind(i32* %68)
br label %70
70: ; preds = %75, %67
%71 = load i32*, i32** %5
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%73 = call i64 @fscanf(i32* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = icmp sgt i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%77 = call i32 @puts(i8* %76)
br label %70
78: ; preds = %70
%79 = load i32*, i32** %5
%80 = call i64 @fclose(i32* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %85
85: ; preds = %82, %78
br label %25
86: ; preds = %19
%87 = load i32, i32* %3
%88 = call i32 @close(i32 %87)
br label %9
}

LLVM IR (-O2):
@.str = [7 x i8] c"accept\00"
@.str.1 = [3 x i8] c"w+\00"
@stdout = global i32 0
@.str.2 = [26 x i8] c"Probl\C3\A8me socket client.\0A\00"
@.str.3 = [10 x i8] c"<pawnee>\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"Erreur fermeture fichier\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = tail call i32 @creer_serveur(i32 8000)
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %65, %0
%5 = tail call i32 @accept(i32 %2, i32* null, i32* null)
%6 = tail call i32 @traitement_signal(i32 %5)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %5, -1
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = tail call i32 (...) @initialiser_signaux()
%13 = tail call i32 @sleep(i32 1)
%14 = icmp eq i32 %7, 0
br i1 %14, label %15, label %65
15: ; preds = %11
%16 = call i32* @fdopen(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %62, %15
%19 = load i32, i32* @stdout
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15, %62
%23 = phi i32* [ %63, %62 ], [ %16, %15 ]
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32* @fgets(i8* %3, i32 50, i32* %23)
%26 = icmp ne i32* %25, null
%27 = load i8, i8* %3
%28 = icmp ne i8 %27, 0
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %30, label %48
30: ; preds = %22, %42
%31 = call i32 @verif(i8* %3)
br label %32
32: ; preds = %32, %30
%33 = call i32* @fgets(i8* %3, i32 50, i32* %23)
%34 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %33, i32 2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %32
36: ; preds = %32
%37 = icmp eq i32 %31, -1
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @afficherErreur400(i32 %5)
br label %42
40: ; preds = %36
%41 = call i32 @afficherBienvenue(i32 %5)
br label %42
42: ; preds = %40, %38
%43 = call i32* @fgets(i8* %3, i32 50, i32* %23)
%44 = icmp ne i32* %43, null
%45 = load i8, i8* %3
%46 = icmp ne i8 %45, 0
%47 = select i1 %44, i1 %46, i1 false
br i1 %47, label %30, label %48
48: ; preds = %42, %22
%49 = call i32 @rewind(i32* %23)
%50 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%51 = icmp sgt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48, %52
%53 = call i32 @puts(i8* %3)
%54 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%55 = icmp sgt i64 %54, 0
br i1 %55, label %52, label %56
56: ; preds = %52, %48
%57 = call i64 @fclose(i32* %23)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %59, %56
%63 = call i32* @fdopen(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%64 = icmp eq i32* %63, null
br i1 %64, label %18, label %22
65: ; preds = %11
%66 = tail call i32 @close(i32 %5)
br label %4
}