#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*/ fgets(char *, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, size_t);
char *strtok(char *, char *);
int chat(int sock, char *name, char *recv_name, char *buffer,
         char *recv_buffer) {
  size_t mematch, partmatch;
  mematch = (3 * sizeof(char));
  partmatch = (5 * sizeof(char));
  char *mebuffer;
  mebuffer = malloc(256 * sizeof(char));
  send(sock, name, 32, 0);
  recv(sock, recv_name, 32, 0);
  printf("Now talking to %s\n", recv_name);
  while ((strcmp(buffer, "/quit\n")) != 0) {
    send(sock, buffer, 256, 0);
    recv(sock, recv_buffer, 256, 0);
    if ((strcmp(recv_buffer, "/quit\n")) == 0) {
      return 0;
      break;
    }
    if ((strncmp(recv_buffer, "/me", mematch)) == 0) {
      mebuffer = strtok(recv_buffer, " ");
      mebuffer = strtok(NULL, "");
      printf("*%s %s%s: ", recv_name, mebuffer, name);
    } else if ((strncmp(buffer, "/part", partmatch)) == 0) {
      return 1;
      break;
    } else if ((strncmp(buffer, "/join", partmatch)) == 0) {
      return 2;
      break;
    } else {
      printf("%s: %s%s: ", recv_name, recv_buffer, name);
    }
    fgets(buffer, 250, stdin);
  }
}


x86 assembly (clang, -O0):
<chat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x3,-0x30(%rbp)
movq   $0x5,-0x38(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x18(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1350 <chat+0x1d0>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x28(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1257 <chat+0xd7>
movl   $0x0,-0x4(%rbp)
jmp    1350 <chat+0x1d0>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdb4(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12bc <chat+0x13c>
mov    -0x28(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7e(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1334 <chat+0x1b4>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd5e(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12e6 <chat+0x166>
movl   $0x1,-0x4(%rbp)
jmp    1350 <chat+0x1d0>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd3a(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1310 <chat+0x190>
movl   $0x2,-0x4(%rbp)
jmp    1350 <chat+0x1d0>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    132f <chat+0x1af>
jmp    1334 <chat+0x1b4>
mov    -0x20(%rbp),%rdi
mov    0x2ca9(%rip),%rax
mov    (%rax),%edx
mov    $0xfa,%esi
call   1070 <fgets@plt>
jmp    11f1 <chat+0x71>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
mov    $0x20,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xe53(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12d1 <chat+0x161>
lea    0xe3d(%rip),%r13
xor    %eax,%eax
mov    %rax,(%rsp)
jmp    123e <chat+0xce>
xchg   %ax,%ax
mov    %r14,%rdi
lea    0xe54(%rip),%rsi
call   1090 <strtok@plt>
xor    %edi,%edi
lea    0xe1a(%rip),%rsi
call   1090 <strtok@plt>
lea    0xe1a(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfa,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12e3 <chat+0x173>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12e3 <chat+0x173>
mov    $0x3,%edx
mov    %r14,%rdi
lea    0xd9b(%rip),%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     11e0 <chat+0x70>
mov    $0x5,%edx
mov    %rbx,%rdi
lea    0xd8d(%rip),%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     12d3 <chat+0x163>
mov    $0x5,%edx
mov    %rbx,%rdi
lea    0xd7a(%rip),%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
je     12da <chat+0x16a>
lea    0xd6f(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
jmp    120a <chat+0x9a>
jmp    12df <chat+0x16f>
mov    $0x1,%eax
jmp    12df <chat+0x16f>
mov    $0x2,%eax
mov    %rax,(%rsp)
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Now talking to %s\0A\00"
@.str.1 = [7 x i8] c"/quit\0A\00"
@.str.2 = [4 x i8] c"/me\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [11 x i8] c"*%s %s%s: \00"
@.str.6 = [6 x i8] c"/part\00"
@.str.7 = [6 x i8] c"/join\00"
@.str.8 = [11 x i8] c"%s: %s%s: \00"
@stdin = global i32 0
define i32 @chat(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i64 3, i64* %12
store i64 5, i64* %13
%15 = call i8* @malloc(i32 256)
store i8* %15, i8** %14
%16 = load i32, i32* %7
%17 = load i8*, i8** %8
%18 = call i32 @send(i32 %16, i8* %17, i32 32, i32 0)
%19 = load i32, i32* %7
%20 = load i8*, i8** %9
%21 = call i32 @recv(i32 %19, i8* %20, i32 32, i32 0)
%22 = load i8*, i8** %9
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %71, %5
%25 = load i8*, i8** %10
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %75
28: ; preds = %24
%29 = load i32, i32* %7
%30 = load i8*, i8** %10
%31 = call i32 @send(i32 %29, i8* %30, i32 256, i32 0)
%32 = load i32, i32* %7
%33 = load i8*, i8** %11
%34 = call i32 @recv(i32 %32, i8* %33, i32 256, i32 0)
%35 = load i8*, i8** %11
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %28
store i32 0, i32* %6
br label %75
39: ; preds = %28
%40 = load i8*, i8** %11
%41 = load i64, i64* %12
%42 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = load i8*, i8** %11
%46 = call i8* @strtok(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %46, i8** %14
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i8* %47, i8** %14
%48 = load i8*, i8** %9
%49 = load i8*, i8** %14
%50 = load i8*, i8** %8
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %48, i8* %49, i8* %50)
br label %71
52: ; preds = %39
%53 = load i8*, i8** %10
%54 = load i64, i64* %13
%55 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %52
store i32 1, i32* %6
br label %75
58: ; preds = %52
%59 = load i8*, i8** %10
%60 = load i64, i64* %13
%61 = call i64 @strncmp(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i64 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %58
store i32 2, i32* %6
br label %75
64: ; preds = %58
%65 = load i8*, i8** %9
%66 = load i8*, i8** %11
%67 = load i8*, i8** %8
%68 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %65, i8* %66, i8* %67)
br label %69
69: ; preds = %64
br label %70
70: ; preds = %69
br label %71
71: ; preds = %70, %44
%72 = load i8*, i8** %10
%73 = load i32, i32* @stdin
%74 = call i32 @fgets(i8* %72, i32 250, i32 %73)
br label %24
75: ; preds = %38, %57, %63, %24
%76 = load i32, i32* %6
ret i32 %76
}

LLVM IR (-O2):
@.str = [19 x i8] c"Now talking to %s\0A\00"
@.str.1 = [7 x i8] c"/quit\0A\00"
@.str.2 = [4 x i8] c"/me\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [11 x i8] c"*%s %s%s: \00"
@.str.6 = [6 x i8] c"/part\00"
@.str.7 = [6 x i8] c"/join\00"
@.str.8 = [11 x i8] c"%s: %s%s: \00"
@stdin = global i32 0
define i32 @chat(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i32 @send(i32 %0, i8* %1, i32 32, i32 0)
%7 = tail call i32 @recv(i32 %0, i8* %2, i32 32, i32 0)
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %36, label %11
11: ; preds = %5, %31
%12 = tail call i32 @send(i32 %0, i8* %3, i32 256, i32 0)
%13 = tail call i32 @recv(i32 %0, i8* %4, i32 256, i32 0)
%14 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %36, label %16
16: ; preds = %11
%17 = tail call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %21, i8* %1)
br label %31
23: ; preds = %16
%24 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %23
%27 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i64 5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %2, i8* %4, i8* %1)
br label %31
31: ; preds = %29, %19
%32 = load i32, i32* @stdin
%33 = tail call i32 @fgets(i8* %3, i32 250, i32 %32)
%34 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %11
36: ; preds = %11, %23, %26, %31, %5
%37 = phi i32 [ undef, %5 ], [ undef, %31 ], [ 2, %26 ], [ 1, %23 ], [ 0, %11 ]
ret i32 %37
}