#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*/ disconnect_client(int, char *);
int read_in(int, char *, int);
int /*<<< orphan*/ say(int, char *);
scalar_t__ strncasecmp(char *, char *, int);
void service_client(int socket) {
  char *questions[] = {
      "Knock! Knock!\r\n",
      "Oscar\r\n",
  };
  char *valid_answers[] = {
      "Who's there?",
      "Oscar who?",
  };
  char *final_sentence = "Oscar silly question, you get a silly answer\r\n";
  char answer[80];
  char silence[] = "Next time say something\r\n";
  char wrong_answer[] = "Wrong answer\r\n";
  int i;
  for (i = 0; i < 2; i++) {
    say(socket, questions[i]);
    if (read_in(socket, answer, 80) < 3) {
      disconnect_client(socket, silence);
      return;
    } else if (strncasecmp(answer, valid_answers[i], 80) != 0) {
      disconnect_client(socket, wrong_answer);
      return;
    }
  }
  disconnect_client(socket, final_sentence);
}


x86 assembly (clang, -O0):
<service_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ca8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2ca5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca2(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeaf(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xee4(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xed2(%rip),%ax
mov    %ax,-0x98(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0xbf(%rbp)
mov    0xe96(%rip),%eax
mov    %eax,-0xb7(%rbp)
mov    0xe8d(%rip),%ax
mov    %ax,-0xb3(%rbp)
mov    0xe82(%rip),%al
mov    %al,-0xb1(%rbp)
movl   $0x0,-0xc4(%rbp)
cmpl   $0x2,-0xc4(%rbp)
jge    12a6 <service_client+0x166>
mov    -0x4(%rbp),%edi
movslq -0xc4(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rsi
call   1060 <say@plt>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
call   1050 <read_in@plt>
cmp    $0x3,%eax
jge    124d <service_client+0x10d>
mov    -0x4(%rbp),%edi
lea    -0xb0(%rbp),%rsi
call   1030 <disconnect_client@plt>
jmp    12b2 <service_client+0x172>
lea    -0x90(%rbp),%rdi
movslq -0xc4(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
mov    $0x50,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
je     1288 <service_client+0x148>
mov    -0x4(%rbp),%edi
lea    -0xbf(%rbp),%rsi
call   1030 <disconnect_client@plt>
jmp    12b2 <service_client+0x172>
jmp    128d <service_client+0x14d>
jmp    1292 <service_client+0x152>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    11fb <service_client+0xbb>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1030 <disconnect_client@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_client>:
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ebx
movups 0xf29(%rip),%xmm0
movups %xmm0,0x1a(%rsp)
movaps 0xf13(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa0d726577736e,%rax
mov    %rax,0x7(%rsp)
movabs $0x6e6120676e6f7257,%rax
20 61 6e
mov    %rax,(%rsp)
lea    0xe7a(%rip),%rsi
call   1060 <say@plt>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x50,%edx
call   1050 <read_in@plt>
cmp    $0x3,%eax
jge    11a8 <service_client+0x68>
lea    0x10(%rsp),%rsi
jmp    11c6 <service_client+0x86>
lea    0xe69(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    $0x50,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     11d6 <service_client+0x96>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1030 <disconnect_client@plt>
add    $0x80,%rsp
pop    %rbx
ret
lea    0xe33(%rip),%rsi
mov    %ebx,%edi
call   1060 <say@plt>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x50,%edx
call   1050 <read_in@plt>
cmp    $0x3,%eax
jl     11a1 <service_client+0x61>
lea    0xe24(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    $0x50,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
jne    11c3 <service_client+0x83>
lea    0xe14(%rip),%rsi
jmp    11c6 <service_client+0x86>

LLVM IR (-O0):
@.str = [16 x i8] c"Knock! Knock!\0D\0A\00"
@.str.1 = [8 x i8] c"Oscar\0D\0A\00"
@__const.service_client.questions = [2 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [13 x i8] c"Who's there?\00"
@.str.3 = [11 x i8] c"Oscar who?\00"
@__const.service_client.valid_answers = [2 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [47 x i8] c"Oscar silly question, you get a silly answer\0D\0A\00"
@__const.service_client.silence = [26 x i8] c"Next time say something\0D\0A\00"
@__const.service_client.wrong_answer = [15 x i8] c"Wrong answer\0D\0A\00"
define void @service_client(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i8*]
%4 = alloca [2 x i8*]
%5 = alloca i8*
%6 = alloca [80 x i8]
%7 = alloca [26 x i8]
%8 = alloca [15 x i8]
%9 = alloca i32
store i32 %0, i32* %2
%10 = bitcast [2 x i8*]* %3 to i8*
%11 = bitcast [2 x i8*]* %4 to i8*
store i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8** %5
%12 = bitcast [26 x i8]* %7 to i8*
%13 = bitcast [15 x i8]* %8 to i8*
store i32 0, i32* %9
br label %14
14: ; preds = %46, %1
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %49
17: ; preds = %14
%18 = load i32, i32* %2
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @say(i32 %18, i8* %22)
%24 = load i32, i32* %2
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%26 = call i32 @read_in(i32 %24, i8* %25, i32 80)
%27 = icmp slt i32 %26, 3
br i1 %27, label %28, label %32
28: ; preds = %17
%29 = load i32, i32* %2
%30 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%31 = call i32 @disconnect_client(i32 %29, i8* %30)
br label %53
32: ; preds = %17
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 %35
%37 = load i8*, i8** %36
%38 = call i64 @strncasecmp(i8* %33, i8* %37, i32 80)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* %2
%42 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%43 = call i32 @disconnect_client(i32 %41, i8* %42)
br label %53
44: ; preds = %32
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %14
49: ; preds = %14
%50 = load i32, i32* %2
%51 = load i8*, i8** %5
%52 = call i32 @disconnect_client(i32 %50, i8* %51)
br label %53
53: ; preds = %49, %40, %28
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Knock! Knock!\0D\0A\00"
@.str.1 = [8 x i8] c"Oscar\0D\0A\00"
@.str.2 = [13 x i8] c"Who's there?\00"
@.str.3 = [11 x i8] c"Oscar who?\00"
@.str.4 = [47 x i8] c"Oscar silly question, you get a silly answer\0D\0A\00"
@__const.service_client.silence = [26 x i8] c"Next time say something\0D\0A\00"
@__const.service_client.wrong_answer = [15 x i8] c"Wrong answer\0D\0A\00"
define void @service_client(i32 %0) {
%2 = alloca [80 x i8]
%3 = alloca [26 x i8]
%4 = alloca [15 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%8 = call i32 @say(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @read_in(i32 %0, i8* %5, i32 80)
%10 = icmp slt i32 %9, 3
br i1 %10, label %20, label %22
11: ; preds = %22
%12 = call i32 @say(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @read_in(i32 %0, i8* %5, i32 80)
%14 = icmp slt i32 %13, 3
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = call i64 @strncasecmp(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 80)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = call i32 @disconnect_client(i32 %0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %27
20: ; preds = %11, %1
%21 = call i32 @disconnect_client(i32 %0, i8* %6)
br label %27
22: ; preds = %1
%23 = call i64 @strncasecmp(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 80)
%24 = icmp eq i64 %23, 0
br i1 %24, label %11, label %25
25: ; preds = %15, %22
%26 = call i32 @disconnect_client(i32 %0, i8* %7)
br label %27
27: ; preds = %18, %25, %20
ret void
}