#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 */
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ otp_decode(char *, int *, int);
int /*<<< orphan*/ otp_decrypt(int *, int *, int *, int);
int /*<<< orphan*/ otp_encode(int *, char *);
int /*<<< orphan*/ otp_encrypt(int *, int *, int *, int);
int /*<<< orphan*/ pullFromSocket(int, char *, size_t);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int);
void handleClient(int clientFd, int encryptionMode, char *buffer,
                  int *resultBuffer, int *keyBuffer, int *msgBuffer) {
  ssize_t receiveLength;
  ssize_t sendSuccess;
  size_t msgAndKeyLength;
  size_t isEncrypting;
  while (1) {
    receiveLength = recv(clientFd, buffer, sizeof(size_t) * 2, 0);
    if (!receiveLength)
      return;
    isEncrypting = ((size_t *)buffer)[0];
    msgAndKeyLength = ((size_t *)buffer)[1];
    if (isEncrypting != encryptionMode) {
      shutdown(clientFd, 2);
      close(clientFd);
      return;
    }
    pullFromSocket(clientFd, buffer, msgAndKeyLength);
    buffer[msgAndKeyLength] = '\0';
    otp_encode(keyBuffer, buffer);
    pullFromSocket(clientFd, buffer, msgAndKeyLength);
    buffer[msgAndKeyLength] = '\0';
    otp_encode(msgBuffer, buffer);
    if (encryptionMode)
      otp_encrypt(resultBuffer, msgBuffer, keyBuffer, (int)msgAndKeyLength);
    else
      otp_decrypt(resultBuffer, msgBuffer, keyBuffer, (int)msgAndKeyLength);
    otp_decode(buffer, resultBuffer, (int)msgAndKeyLength);
    sendSuccess = send(clientFd, buffer, msgAndKeyLength, 0);
    if (!sendSuccess)
      return;
  }
}


x86 assembly (clang, -O0):
<handleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11d3 <handleClient+0x43>
jmp    12e0 <handleClient+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
je     1215 <handleClient+0x85>
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1090 <close@plt>
jmp    12e0 <handleClient+0x150>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <pullFromSocket@plt>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <otp_encode@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <pullFromSocket@plt>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <otp_encode@plt>
cmpl   $0x0,-0x8(%rbp)
je     128d <handleClient+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    %eax,%ecx
call   1060 <otp_encrypt@plt>
jmp    12a4 <handleClient+0x114>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    %eax,%ecx
call   1080 <otp_decrypt@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
call   10a0 <otp_decode@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    12db <handleClient+0x14b>
jmp    12e0 <handleClient+0x150>
jmp    11ae <handleClient+0x1e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleClient>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %edi,%ebp
mov    %esi,0xc(%rsp)
movslq %esi,%rax
mov    %rax,0x10(%rsp)
jmp    11f2 <handleClient+0x62>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1080 <otp_decrypt@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   10a0 <otp_decode@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
je     1270 <handleClient+0xe0>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1270 <handleClient+0xe0>
mov    0x10(%rsp),%rax
cmp    %rax,(%rbx)
jne    127f <handleClient+0xef>
mov    0x8(%rbx),%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <pullFromSocket@plt>
movb   $0x0,(%rbx,%r13,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <otp_encode@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <pullFromSocket@plt>
movb   $0x0,(%rbx,%r13,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <otp_encode@plt>
cmpl   $0x0,0xc(%rsp)
je     11c0 <handleClient+0x30>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1060 <otp_encrypt@plt>
jmp    11d1 <handleClient+0x41>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebp,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <close@plt>

LLVM IR (-O0):
define void @handleClient(i32 %0, i32 %1, i8* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
br label %17
17: ; preds = %6, %92
%18 = load i32, i32* %7
%19 = load i8*, i8** %9
%20 = call i32 @recv(i32 %18, i8* %19, i32 16, i32 0)
store i32 %20, i32* %13
%21 = load i32, i32* %13
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
br label %93
24: ; preds = %17
%25 = load i8*, i8** %9
%26 = bitcast i8* %25 to i64*
%27 = getelementptr inbounds i64, i64* %26, i64 0
%28 = load i64, i64* %27
store i64 %28, i64* %16
%29 = load i8*, i8** %9
%30 = bitcast i8* %29 to i64*
%31 = getelementptr inbounds i64, i64* %30, i64 1
%32 = load i64, i64* %31
store i64 %32, i64* %15
%33 = load i64, i64* %16
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = icmp ne i64 %33, %35
br i1 %36, label %37, label %42
37: ; preds = %24
%38 = load i32, i32* %7
%39 = call i32 @shutdown(i32 %38, i32 2)
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
br label %93
42: ; preds = %24
%43 = load i32, i32* %7
%44 = load i8*, i8** %9
%45 = load i64, i64* %15
%46 = call i32 @pullFromSocket(i32 %43, i8* %44, i64 %45)
%47 = load i8*, i8** %9
%48 = load i64, i64* %15
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 0, i8* %49
%50 = load i32*, i32** %11
%51 = load i8*, i8** %9
%52 = call i32 @otp_encode(i32* %50, i8* %51)
%53 = load i32, i32* %7
%54 = load i8*, i8** %9
%55 = load i64, i64* %15
%56 = call i32 @pullFromSocket(i32 %53, i8* %54, i64 %55)
%57 = load i8*, i8** %9
%58 = load i64, i64* %15
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8 0, i8* %59
%60 = load i32*, i32** %12
%61 = load i8*, i8** %9
%62 = call i32 @otp_encode(i32* %60, i8* %61)
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %42
%66 = load i32*, i32** %10
%67 = load i32*, i32** %12
%68 = load i32*, i32** %11
%69 = load i64, i64* %15
%70 = trunc i64 %69 to i32
%71 = call i32 @otp_encrypt(i32* %66, i32* %67, i32* %68, i32 %70)
br label %79
72: ; preds = %42
%73 = load i32*, i32** %10
%74 = load i32*, i32** %12
%75 = load i32*, i32** %11
%76 = load i64, i64* %15
%77 = trunc i64 %76 to i32
%78 = call i32 @otp_decrypt(i32* %73, i32* %74, i32* %75, i32 %77)
br label %79
79: ; preds = %72, %65
%80 = load i8*, i8** %9
%81 = load i32*, i32** %10
%82 = load i64, i64* %15
%83 = trunc i64 %82 to i32
%84 = call i32 @otp_decode(i8* %80, i32* %81, i32 %83)
%85 = load i32, i32* %7
%86 = load i8*, i8** %9
%87 = load i64, i64* %15
%88 = call i32 @send(i32 %85, i8* %86, i64 %87, i32 0)
store i32 %88, i32* %14
%89 = load i32, i32* %14
%90 = icmp ne i32 %89, 0
br i1 %90, label %92, label %91
91: ; preds = %79
br label %93
92: ; preds = %79
br label %17
93: ; preds = %91, %37, %23
ret void
}

LLVM IR (-O2):
define void @handleClient(i32 %0, i32 %1, i8* %2, i32* %3, i32* %4, i32* %5) {
%7 = bitcast i8* %2 to i64*
%8 = getelementptr inbounds i8, i8* %2, i64 8
%9 = bitcast i8* %8 to i64*
%10 = sext i32 %1 to i64
%11 = icmp eq i32 %1, 0
br label %12
12: ; preds = %33, %6
%13 = tail call i32 @recv(i32 %0, i8* %2, i32 16, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %37, label %15
15: ; preds = %12
%16 = load i64, i64* %7
%17 = load i64, i64* %9
%18 = icmp eq i64 %16, %10
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @shutdown(i32 %0, i32 2)
%21 = tail call i32 @close(i32 %0)
br label %37
22: ; preds = %15
%23 = tail call i32 @pullFromSocket(i32 %0, i8* %2, i64 %17)
%24 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 0, i8* %24
%25 = tail call i32 @otp_encode(i32* %4, i8* %2)
%26 = tail call i32 @pullFromSocket(i32 %0, i8* %2, i64 %17)
store i8 0, i8* %24
%27 = tail call i32 @otp_encode(i32* %5, i8* %2)
%28 = trunc i64 %17 to i32
br i1 %11, label %31, label %29
29: ; preds = %22
%30 = tail call i32 @otp_encrypt(i32* %3, i32* %5, i32* %4, i32 %28)
br label %33
31: ; preds = %22
%32 = tail call i32 @otp_decrypt(i32* %3, i32* %5, i32* %4, i32 %28)
br label %33
33: ; preds = %31, %29
%34 = tail call i32 @otp_decode(i8* %2, i32* %3, i32 %28)
%35 = tail call i32 @send(i32 %0, i8* %2, i64 %17, i32 0)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %12
37: ; preds = %33, %12, %19
ret void
}