#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ start_tsung_player(char *);
scalar_t__ stop_tsung_player(char *);
scalar_t__ strcmp(char *, char *);
int handle_client(int connfd, char *prefix) {
  char buf[5];
  int recved = 0;
  int n = 0;
  int keepgoing = 1;
  while (keepgoing) {
    n = recv(connfd, buf + recved, 4 - recved, 0);
    if (n < 0) {
      perror("Recv failed");
      return 2;
    }
    recved += n;
    if (recved == 4) {
      keepgoing = 0;
    }
  }
  buf[4] = '\0';
  if (strcmp(buf, "STRT") == 0) {
    if (start_tsung_player(prefix)) {
      if (send(connfd, "NO\n", 3, 0) < 0) {
        perror("Send failed");
        return 2;
      }
    }
    if (send(connfd, "OK\n", 3, 0) < 0) {
      perror("Send failed");
      return 2;
    }
  } else if (strcmp(buf, "STOP") == 0) {
    if (stop_tsung_player(prefix)) {
      if (send(connfd, "NO\n", 3, 0) < 0) {
        perror("Send failed");
        return 2;
      }
    }
    if (send(connfd, "OK\n", 3, 0) < 0) {
      perror("Send failed");
      return 2;
    }
  } else if (strcmp(buf, "STDN") == 0) {
    printf("Shutting down the server.\n");
    if (send(connfd, "BY\n", 3, 0) < 0) {
      perror("Send failed");
      return 2;
    }
    return 0;
  } else {
    printf("I would close the connection.\n");
    return 2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<handle_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ff <handle_client+0x8f>
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x4,%edx
sub    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11e0 <handle_client+0x70>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    11fa <handle_client+0x8a>
movl   $0x0,-0x24(%rbp)
jmp    1194 <handle_client+0x24>
movb   $0x0,-0x11(%rbp)
lea    -0x15(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12aa <handle_client+0x13a>
mov    -0x10(%rbp),%rdi
call   1070 <start_tsung_player@plt>
cmp    $0x0,%rax
je     126d <handle_client+0xfd>
mov    -0x8(%rbp),%edi
lea    0xdd7(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    1268 <handle_client+0xf8>
lea    0xdbe(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
jmp    126d <handle_client+0xfd>
mov    -0x8(%rbp),%edi
lea    0xdaa(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    12a5 <handle_client+0x135>
lea    0xd81(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
jmp    13d8 <handle_client+0x268>
lea    -0x15(%rbp),%rdi
lea    0xd70(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1351 <handle_client+0x1e1>
mov    -0x10(%rbp),%rdi
call   1090 <stop_tsung_player@plt>
cmp    $0x0,%rax
je     1314 <handle_client+0x1a4>
mov    -0x8(%rbp),%edi
lea    0xd30(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    130f <handle_client+0x19f>
lea    0xd17(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
jmp    1314 <handle_client+0x1a4>
mov    -0x8(%rbp),%edi
lea    0xd03(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    134c <handle_client+0x1dc>
lea    0xcda(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
jmp    13d3 <handle_client+0x263>
lea    -0x15(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    13bb <handle_client+0x24b>
lea    0xcbd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xcc9(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    13af <handle_client+0x23f>
lea    0xc77(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
movl   $0x0,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
lea    0xc8c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13df <handle_client+0x26f>
jmp    13d8 <handle_client+0x268>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
nop
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0xb,%rsi
mov    $0x4,%edx
sub    %eax,%edx
mov    %ebx,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     128a <handle_client+0x11a>
add    %eax,%ebp
cmp    $0x4,%ebp
jne    1180 <handle_client+0x10>
movb   $0x0,0xf(%rsp)
lea    0xe56(%rip),%rsi
lea    0xb(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1202 <handle_client+0x92>
lea    0xe59(%rip),%rsi
lea    0xb(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1211 <handle_client+0xa1>
lea    0xe48(%rip),%rsi
lea    0xb(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1259 <handle_client+0xe9>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
jmp    1296 <handle_client+0x126>
mov    %r14,%rdi
call   1070 <start_tsung_player@plt>
test   %rax,%rax
jne    121e <handle_client+0xae>
jmp    1238 <handle_client+0xc8>
mov    %r14,%rdi
call   1090 <stop_tsung_player@plt>
test   %rax,%rax
je     1238 <handle_client+0xc8>
lea    0xdec(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
js     1281 <handle_client+0x111>
lea    0xde2(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    $0x1,%ebp
test   %rax,%rax
jns    129b <handle_client+0x12b>
jmp    1281 <handle_client+0x111>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc3(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
jns    129b <handle_client+0x12b>
lea    0xd8d(%rip),%rdi
jmp    1291 <handle_client+0x121>
lea    0xd6f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Recv failed\00"
@.str.1 = [5 x i8] c"STRT\00"
@.str.2 = [4 x i8] c"NO\0A\00"
@.str.3 = [12 x i8] c"Send failed\00"
@.str.4 = [4 x i8] c"OK\0A\00"
@.str.5 = [5 x i8] c"STOP\00"
@.str.6 = [5 x i8] c"STDN\00"
@.str.7 = [27 x i8] c"Shutting down the server.\0A\00"
@.str.8 = [4 x i8] c"BY\0A\00"
@.str.9 = [31 x i8] c"I would close the connection.\0A\00"
define i32 @handle_client(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [5 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
br label %10
10: ; preds = %33, %2
%11 = load i32, i32* %9
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = load i32, i32* %4
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %7
%20 = sub nsw i32 4, %19
%21 = call i32 @recv(i32 %14, i8* %18, i32 %20, i32 0)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %95
26: ; preds = %13
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = add nsw i32 %28, %27
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 4
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 0, i32* %9
br label %33
33: ; preds = %32, %26
br label %10
34: ; preds = %10
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
store i8 0, i8* %35
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %57
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = call i64 @start_tsung_player(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* %4
%45 = call i64 @send(i32 %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %95
49: ; preds = %43
br label %50
50: ; preds = %49, %39
%51 = load i32, i32* %4
%52 = call i64 @send(i32 %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 0)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %95
56: ; preds = %50
br label %94
57: ; preds = %34
%58 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %79
61: ; preds = %57
%62 = load i8*, i8** %5
%63 = call i64 @stop_tsung_player(i8* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %61
%66 = load i32, i32* %4
%67 = call i64 @send(i32 %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %95
71: ; preds = %65
br label %72
72: ; preds = %71, %61
%73 = load i32, i32* %4
%74 = call i64 @send(i32 %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 0)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %95
78: ; preds = %72
br label %93
79: ; preds = %57
%80 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %91
83: ; preds = %79
%84 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%85 = load i32, i32* %4
%86 = call i64 @send(i32 %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 3, i32 0)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %83
%89 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %95
90: ; preds = %83
store i32 0, i32* %3
br label %95
91: ; preds = %79
%92 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
store i32 2, i32* %3
br label %95
93: ; preds = %78
br label %94
94: ; preds = %93, %56
store i32 1, i32* %3
br label %95
95: ; preds = %94, %91, %90, %88, %76, %69, %54, %47, %24
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@.str = [12 x i8] c"Recv failed\00"
@.str.1 = [5 x i8] c"STRT\00"
@.str.2 = [4 x i8] c"NO\0A\00"
@.str.3 = [12 x i8] c"Send failed\00"
@.str.4 = [4 x i8] c"OK\0A\00"
@.str.5 = [5 x i8] c"STOP\00"
@.str.6 = [5 x i8] c"STDN\00"
@.str.8 = [4 x i8] c"BY\0A\00"
@str = [30 x i8] c"I would close the connection.\00"
@str.10 = [26 x i8] c"Shutting down the server.\00"
define i32 @handle_client(i32 %0, i8* %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %14
%6 = phi i32 [ 0, %2 ], [ %15, %14 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %7
%9 = sub nsw i32 4, %6
%10 = call i32 @recv(i32 %0, i8* %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %61
14: ; preds = %5
%15 = add nsw i32 %10, %6
%16 = icmp eq i32 %15, 4
br i1 %16, label %17, label %5
17: ; preds = %14
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
store i8 0, i8* %18
%19 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = call i64 @start_tsung_player(i8* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = call i64 @send(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %61
29: ; preds = %24, %21
%30 = call i64 @send(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %61
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %61
34: ; preds = %17
%35 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = call i64 @stop_tsung_player(i8* %1)
%39 = icmp eq i64 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %37
%41 = call i64 @send(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %61
45: ; preds = %40, %37
%46 = call i64 @send(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 0)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %61
50: ; preds = %34
%51 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%55 = call i64 @send(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 3, i32 0)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %61
59: ; preds = %50
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %61
61: ; preds = %29, %45, %53, %59, %57, %48, %43, %32, %27, %12
%62 = phi i32 [ 2, %12 ], [ 2, %27 ], [ 2, %32 ], [ 2, %43 ], [ 2, %48 ], [ 2, %57 ], [ 2, %59 ], [ 0, %53 ], [ 1, %45 ], [ 1, %29 ]
ret i32 %62
}