#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 */
char *crea_phrase(char *, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ write_server(int, char *);
write_sentence(int socket_descriptor) {
  printf("\nVous etes leader, quelle phrase envoyer? (au format XXX_XX ou X "
         "peut etre nul) : ");
  char *mesg = malloc(195 * sizeof(char));
  char *clean = malloc((strlen(mesg) + 2) * sizeof(char));
  fgets(mesg, 195, stdin);
  while ((strlen(mesg) < 0) && (strstr(mesg, "_") == NULL) &&
         (strstr(mesg, "~") == NULL)) {
    printf("\nLe message doit contenir le mot _ pour signifier la partie a "
           "completer.");
    printf("\nIl ne peut pas contenir le charactere ~ ni _\n");
    fgets(mesg, 195, stdin);
  }
  if (mesg[0] == '_') {
    memcpy(clean, " ", 1);
    memcpy(clean + 1, mesg, strlen(mesg));
    memcpy(mesg, clean, strlen(clean));
  }
  if (mesg[strlen(mesg) - 2] == '_') {
    memcpy(clean, mesg, strlen(mesg) - 1);
    memcpy(clean + strlen(mesg) - 1, " \0", 2);
    memcpy(mesg, clean, strlen(clean));
  }
  char *str = malloc((strlen(mesg) + 5) * sizeof(char));
  str = crea_phrase(mesg, "0001");
  write_server(socket_descriptor, str);
}


x86 assembly (clang, -O0):
<write_sentence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    $0xc3,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    $0xc3,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jge    1231 <write_sentence+0xb1>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    1231 <write_sentence+0xb1>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1241 <write_sentence+0xc1>
jmp    1275 <write_sentence+0xf5>
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
mov    $0xc3,%esi
call   1060 <fgets@plt>
jmp    11dc <write_sentence+0x5c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    12ee <write_sentence+0x16e>
mov    -0x18(%rbp),%rdi
lea    0xdc1(%rip),%rsi
mov    $0x1,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
jne    139a <write_sentence+0x21a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
sub    $0x1,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x68(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    0xd6c(%rip),%rsi
mov    $0x2,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd0d(%rip),%rsi
call   1090 <crea_phrase@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <write_server@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_sentence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0xe5b(%rip),%rdi
call   1060 <printf@plt>
mov    $0xc3,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    0x2e17(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xc3,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     12c7 <write_sentence+0x137>
cmpb   $0x5f,(%rbx)
jne    1238 <write_sentence+0xa8>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1090 <memcpy@plt>
lea    0x1(%r15),%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x5f,-0x2(%rax,%rbx,1)
jne    1297 <write_sentence+0x107>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%r15,%rax,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe57(%rip),%rsi
mov    $0x2,%edx
call   1090 <memcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xdf6(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <crea_phrase@plt>
mov    %r14d,%edi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <write_server@plt>
lea    0xd85(%rip),%r12
lea    0xdcc(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x5f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11f1 <write_sentence+0x61>
mov    %rbx,%rdi
mov    $0x7e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11f1 <write_sentence+0x61>
mov    %r12,%rdi
call   1060 <printf@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xc3,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     12e0 <write_sentence+0x150>
jmp    11f1 <write_sentence+0x61>

LLVM IR (-O0):
@.str = [83 x i8] c"\0AVous etes leader, quelle phrase envoyer? (au format XXX_XX ou X peut etre nul) : \00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"_\00"
@.str.2 = [2 x i8] c"~\00"
@.str.3 = [73 x i8] c"\0ALe message doit contenir le mot _ pour signifier la partie a completer.\00"
@.str.4 = [47 x i8] c"\0AIl ne peut pas contenir le charactere ~ ni _\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [3 x i8] c" \00\00"
@.str.7 = [5 x i8] c"0001\00"
define i32 @write_sentence(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
%7 = call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%8 = call i8* @malloc(i32 195)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 2
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %4
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 195, i32 %17)
br label %19
19: ; preds = %33, %1
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = call i32* @strstr(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i32* @strstr(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br label %31
31: ; preds = %27, %23, %19
%32 = phi i1 [ false, %23 ], [ false, %19 ], [ %30, %27 ]
br i1 %32, label %33, label %39
33: ; preds = %31
%34 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%36 = load i8*, i8** %4
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %36, i32 195, i32 %37)
br label %19
39: ; preds = %31
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 95
br i1 %44, label %45, label %59
45: ; preds = %39
%46 = load i8*, i8** %5
%47 = call i32 @memcpy(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8*, i8** %4
%51 = load i8*, i8** %4
%52 = call i32 @strlen(i8* %51)
%53 = call i32 @memcpy(i8* %49, i8* %50, i32 %52)
%54 = load i8*, i8** %4
%55 = load i8*, i8** %5
%56 = load i8*, i8** %5
%57 = call i32 @strlen(i8* %56)
%58 = call i32 @memcpy(i8* %54, i8* %55, i32 %57)
br label %59
59: ; preds = %45, %39
%60 = load i8*, i8** %4
%61 = load i8*, i8** %4
%62 = call i32 @strlen(i8* %61)
%63 = sub nsw i32 %62, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %60, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 95
br i1 %68, label %69, label %88
69: ; preds = %59
%70 = load i8*, i8** %5
%71 = load i8*, i8** %4
%72 = load i8*, i8** %4
%73 = call i32 @strlen(i8* %72)
%74 = sub nsw i32 %73, 1
%75 = call i32 @memcpy(i8* %70, i8* %71, i32 %74)
%76 = load i8*, i8** %5
%77 = load i8*, i8** %4
%78 = call i32 @strlen(i8* %77)
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %76, i64 %79
%81 = getelementptr inbounds i8, i8* %80, i64 -1
%82 = call i32 @memcpy(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%83 = load i8*, i8** %4
%84 = load i8*, i8** %5
%85 = load i8*, i8** %5
%86 = call i32 @strlen(i8* %85)
%87 = call i32 @memcpy(i8* %83, i8* %84, i32 %86)
br label %88
88: ; preds = %69, %59
%89 = load i8*, i8** %4
%90 = call i32 @strlen(i8* %89)
%91 = add nsw i32 %90, 5
%92 = sext i32 %91 to i64
%93 = mul i64 %92, 1
%94 = trunc i64 %93 to i32
%95 = call i8* @malloc(i32 %94)
store i8* %95, i8** %6
%96 = load i8*, i8** %4
%97 = call i8* @crea_phrase(i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i8* %97, i8** %6
%98 = load i32, i32* %3
%99 = load i8*, i8** %6
%100 = call i32 @write_server(i32 %98, i8* %99)
%101 = load i32, i32* %2
ret i32 %101
}

LLVM IR (-O2):
@.str = [83 x i8] c"\0AVous etes leader, quelle phrase envoyer? (au format XXX_XX ou X peut etre nul) : \00"
@stdin = global i32 0
@.str.3 = [73 x i8] c"\0ALe message doit contenir le mot _ pour signifier la partie a completer.\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [3 x i8] c" \00\00"
@.str.7 = [5 x i8] c"0001\00"
@str = [46 x i8] c"\0AIl ne peut pas contenir le charactere ~ ni _\00"
define i32 @write_sentence(i32 %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(195) i8* @malloc(i32 195)
%4 = tail call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, 2
%6 = tail call i8* @malloc(i32 %5)
%7 = load i32, i32* @stdin
%8 = tail call i32 @fgets(i8* %3, i32 195, i32 %7)
%9 = tail call i32 @strlen(i8* %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %1, %17
%12 = tail call i8* @strchr(i8* dereferenceable(1) %3, i32 95)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = tail call i8* @strchr(i8* dereferenceable(1) %3, i32 126)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @stdin
%21 = tail call i32 @fgets(i8* %3, i32 195, i32 %20)
%22 = tail call i32 @strlen(i8* %3)
%23 = icmp slt i32 %22, 0
br i1 %23, label %11, label %24
24: ; preds = %14, %11, %17, %1
%25 = load i8, i8* %3
%26 = icmp eq i8 %25, 95
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = tail call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%29 = getelementptr inbounds i8, i8* %6, i64 1
%30 = tail call i32 @strlen(i8* %3)
%31 = tail call i32 @memcpy(i8* %29, i8* %3, i32 %30)
%32 = tail call i32 @strlen(i8* %6)
%33 = tail call i32 @memcpy(i8* %3, i8* %6, i32 %32)
br label %34
34: ; preds = %27, %24
%35 = tail call i32 @strlen(i8* %3)
%36 = add nsw i32 %35, -2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 95
br i1 %40, label %41, label %52
41: ; preds = %34
%42 = tail call i32 @strlen(i8* %3)
%43 = add nsw i32 %42, -1
%44 = tail call i32 @memcpy(i8* %6, i8* %3, i32 %43)
%45 = tail call i32 @strlen(i8* %3)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %6, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 -1
%49 = tail call i32 @memcpy(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%50 = tail call i32 @strlen(i8* %6)
%51 = tail call i32 @memcpy(i8* %3, i8* %6, i32 %50)
br label %52
52: ; preds = %41, %34
%53 = tail call i32 @strlen(i8* %3)
%54 = tail call i8* @crea_phrase(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%55 = tail call i32 @write_server(i32 %0, i8* %54)
ret i32 undef
}