#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
char *get_discipline(scalar_t__);
char *get_id(scalar_t__);
char *malloc(int);
int num_of_list();
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strchr(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void *comm(void *arg) {
  int sockcomm = *((int *)arg);
  while (1) {
    char buff[1024];
    int recu = recv(sockcomm, buff, 99 * sizeof(char), 0);
    buff[recu] = '\0';
    if (strncmp(buff, "disp", 4) == 0) {
      int nb = num_of_list();
      char *mess;
      mess = malloc(sizeof(char) * (255));
      sprintf(mess, "%d!", nb);
      send(sockcomm, mess, strlen(mess) * sizeof(char), 0);
    } else if (strncmp(buff, "get ", 4)) {
      char *id = get_id(strchr(buff, ' ') + 1);
      send(sockcomm, id, strlen(id) * sizeof(char), 0);
    } else if (strncmp(buff, "help ", 5)) {
      char *discipline = get_discipline(strchr(buff, ' ') + 1);
      send(sockcomm, discipline, strlen(discipline) * sizeof(char), 0);
    } else if (strncmp(buff, "add ", 4)) {
    } else if (strncmp(buff, "quit", 4)) {
      close(sockcomm);
    }
  }
}


x86 assembly (clang, -O0):
<comm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    0xdff(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1290 <comm+0xe0>
mov    $0x0,%al
call   1050 <num_of_list@plt>
mov    %eax,-0x418(%rbp)
mov    $0xff,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
mov    -0x418(%rbp),%edx
lea    0xdbe(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1409 <comm+0x259>
lea    -0x410(%rbp),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     131a <comm+0x16a>
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10c0 <get_id@plt>
mov    %rax,-0x428(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x428(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1404 <comm+0x254>
lea    -0x410(%rbp),%rdi
lea    0xce6(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13a4 <comm+0x1f4>
lea    -0x410(%rbp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <get_discipline@plt>
mov    %rax,-0x430(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x430(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x430(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    13ff <comm+0x24f>
lea    -0x410(%rbp),%rdi
lea    0xc62(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13cb <comm+0x21b>
jmp    13fa <comm+0x24a>
lea    -0x410(%rbp),%rdi
lea    0xc40(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13f5 <comm+0x245>
mov    -0xc(%rbp),%edi
call   10a0 <close@plt>
jmp    13fa <comm+0x24a>
jmp    13ff <comm+0x24f>
jmp    1404 <comm+0x254>
jmp    1409 <comm+0x259>
jmp    11c8 <comm+0x18>

x86 assembly (clang, -O2):
<comm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    (%rdi),%ebx
mov    %rsp,%r14
lea    0xe33(%rip),%r15
lea    0xe35(%rip),%r13
jmp    121d <comm+0x6d>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <num_of_list@plt>
mov    %eax,%ebp
mov    $0xff,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
lea    0xe05(%rip),%rsi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11e0 <comm+0x30>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
je     1280 <comm+0xd0>
mov    $0x20,%esi
call   1080 <strchr@plt>
lea    0x1(%rax),%rdi
call   10c0 <get_id@plt>
jmp    12ac <comm+0xfc>
cs nopw 0x0(%rax,%rax,1)
lea    0xd87(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %r14,%rdi
test   %rax,%rax
je     12c1 <comm+0x111>
mov    $0x20,%esi
call   1080 <strchr@plt>
lea    0x1(%rax),%rdi
call   1090 <get_discipline@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
jmp    1214 <comm+0x64>
lea    0xd4c(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    121d <comm+0x6d>
mov    %r14,%rdi
lea    0xd34(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     121d <comm+0x6d>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    121d <comm+0x6d>

LLVM IR (-O0):
@.str = [5 x i8] c"disp\00"
@.str.1 = [4 x i8] c"%d!\00"
@.str.2 = [5 x i8] c"get \00"
@.str.3 = [6 x i8] c"help \00"
@.str.4 = [5 x i8] c"add \00"
@.str.5 = [5 x i8] c"quit\00"
define i8* @comm(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
store i32 %12, i32* %3
br label %13
13: ; preds = %1, %87
%14 = load i32, i32* %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i32 @recv(i32 %14, i8* %15, i32 99, i32 0)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %37
23: ; preds = %13
%24 = call i32 (...) @num_of_list()
store i32 %24, i32* %6
%25 = call i8* @malloc(i32 255)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = load i32, i32* %6
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %3
%30 = load i8*, i8** %7
%31 = load i8*, i8** %7
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i32 @send(i32 %29, i8* %30, i32 %35, i32 0)
br label %87
37: ; preds = %13
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %37
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%43 = call i64 @strchr(i8* %42, i8 signext 32)
%44 = add nsw i64 %43, 1
%45 = call i8* @get_id(i64 %44)
store i8* %45, i8** %8
%46 = load i32, i32* %3
%47 = load i8*, i8** %8
%48 = load i8*, i8** %8
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = call i32 @send(i32 %46, i8* %47, i32 %52, i32 0)
br label %86
54: ; preds = %37
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %54
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%60 = call i64 @strchr(i8* %59, i8 signext 32)
%61 = add nsw i64 %60, 1
%62 = call i8* @get_discipline(i64 %61)
store i8* %62, i8** %9
%63 = load i32, i32* %3
%64 = load i8*, i8** %9
%65 = load i8*, i8** %9
%66 = call i32 @strlen(i8* %65)
%67 = sext i32 %66 to i64
%68 = mul i64 %67, 1
%69 = trunc i64 %68 to i32
%70 = call i32 @send(i32 %63, i8* %64, i32 %69, i32 0)
br label %85
71: ; preds = %54
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%73 = call i64 @strncmp(i8* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %71
br label %84
76: ; preds = %71
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%78 = call i64 @strncmp(i8* %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = load i32, i32* %3
%82 = call i32 @close(i32 %81)
br label %83
83: ; preds = %80, %76
br label %84
84: ; preds = %83, %75
br label %85
85: ; preds = %84, %58
br label %86
86: ; preds = %85, %41
br label %87
87: ; preds = %86, %23
br label %13
}

LLVM IR (-O2):
@.str = [5 x i8] c"disp\00"
@.str.1 = [4 x i8] c"%d!\00"
@.str.2 = [5 x i8] c"get \00"
@.str.3 = [6 x i8] c"help \00"
@.str.4 = [5 x i8] c"add \00"
@.str.5 = [5 x i8] c"quit\00"
define noalias i8* @comm(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %44, %1
%7 = call i32 @recv(i32 %4, i8* %5, i32 99, i32 0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = call i32 (...) @num_of_list()
%14 = call dereferenceable_or_null(255) i8* @malloc(i32 255)
%15 = call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%16 = call i32 @strlen(i8* %14)
%17 = call i32 @send(i32 %4, i8* %14, i32 %16, i32 0)
br label %44
18: ; preds = %6
%19 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = call i64 @strchr(i8* %5, i8 signext 32)
%23 = add nsw i64 %22, 1
%24 = call i8* @get_id(i64 %23)
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @send(i32 %4, i8* %24, i32 %25, i32 0)
br label %44
27: ; preds = %18
%28 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %27
%31 = call i64 @strchr(i8* %5, i8 signext 32)
%32 = add nsw i64 %31, 1
%33 = call i8* @get_discipline(i64 %32)
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @send(i32 %4, i8* %33, i32 %34, i32 0)
br label %44
36: ; preds = %27
%37 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = call i32 @close(i32 %4)
br label %44
44: ; preds = %21, %36, %42, %39, %30, %12
br label %6
}