#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*/ Enter();
int /*<<< orphan*/ Read(int, char *);
int /*<<< orphan*/ Write(int, char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
int connection(int sock, char buffer[], char user[]) {
  Read(sock, buffer);
  if (strcasecmp(buffer, "CLOSE") == 0) {
    printf("El usuario %s ha cerrado la conversacion\n", user);
    Enter();
    return (0);
  } else {
    printf("%s: %s\n", user, buffer);
    printf("Resp_a_%s: %s", user);
    bzero(buffer, 1024);
    fgets(buffer, 1024 - 1, stdin);
    fflush(stdin);
    buffer[strlen(buffer) - 1] = '\0';
    if (strcasecmp(buffer, "CLOSE") == 0) {
      Write(sock, "CLOSE");
      return (0);
    } else {
      Write(sock, buffer);
      return (1);
    }
  }
}


x86 assembly (clang, -O0):
<connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <Read@plt>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ee <connection+0x5e>
mov    -0x18(%rbp),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1040 <Enter@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b2 <connection+0x122>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    -0x10(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    $0x3ff,%esi
call   1090 <fgets@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    129f <connection+0x10f>
mov    -0x8(%rbp),%edi
lea    0xd72(%rip),%rsi
call   1080 <Write@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b2 <connection+0x122>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <Write@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r15d
call   1050 <Read@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1247 <connection+0xb7>
lea    0xe6c(%rip),%rdi
xor    %r14d,%r14d
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    0x2def(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1090 <fgets@plt>
mov    0x0(%rbp),%edi
call   10a0 <fflush@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1264 <connection+0xd4>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1080 <Write@plt>
mov    $0x1,%r14d
jmp    1273 <connection+0xe3>
lea    0xdb8(%rip),%rdi
xor    %r14d,%r14d
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <Enter@plt>
jmp    1273 <connection+0xe3>
lea    0xd95(%rip),%rsi
mov    %r15d,%edi
call   1080 <Write@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"CLOSE\00"
@.str.1 = [42 x i8] c"El usuario %s ha cerrado la conversacion\0A\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [14 x i8] c"Resp_a_%s: %s\00"
@stdin = global i32 0
define i32 @connection(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
%9 = load i8*, i8** %6
%10 = call i32 @Read(i32 %8, i8* %9)
%11 = load i8*, i8** %6
%12 = call i64 @strcasecmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 (...) @Enter()
store i32 0, i32* %4
br label %47
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i8*, i8** %6
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %6
%25 = call i32 @bzero(i8* %24, i32 1024)
%26 = load i8*, i8** %6
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %26, i32 1023, i32 %27)
%29 = load i32, i32* @stdin
%30 = call i32 @fflush(i32 %29)
%31 = load i8*, i8** %6
%32 = load i8*, i8** %6
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %31, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %6
%38 = call i64 @strcasecmp(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %18
%41 = load i32, i32* %5
%42 = call i32 @Write(i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %47
43: ; preds = %18
%44 = load i32, i32* %5
%45 = load i8*, i8** %6
%46 = call i32 @Write(i32 %44, i8* %45)
store i32 1, i32* %4
br label %47
47: ; preds = %43, %40, %14
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"CLOSE\00"
@.str.1 = [42 x i8] c"El usuario %s ha cerrado la conversacion\0A\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [14 x i8] c"Resp_a_%s: %s\00"
@stdin = global i32 0
define i32 @connection(i32 %0, i8* %1, i8* %2) {
%4 = tail call i32 @Read(i32 %0, i8* %1)
%5 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%9 = tail call i32 (...) @Enter()
br label %28
10: ; preds = %3
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %1)
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = tail call i32 @bzero(i8* %1, i32 1024)
%14 = load i32, i32* @stdin
%15 = tail call i32 @fgets(i8* %1, i32 1023, i32 %14)
%16 = load i32, i32* @stdin
%17 = tail call i32 @fflush(i32 %16)
%18 = tail call i32 @strlen(i8* %1)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
%22 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %10
%25 = tail call i32 @Write(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %28
26: ; preds = %10
%27 = tail call i32 @Write(i32 %0, i8* %1)
br label %28
28: ; preds = %26, %24, %7
%29 = phi i32 [ 0, %7 ], [ 0, %24 ], [ 1, %26 ]
ret i32 %29
}