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

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int receiveModeMsg(int sock, uint8_t *mode, uint32_t *size, uint32_t *count) {
  *mode = -1;
  char msg[2000];
  memset(msg, 0, 2000);
  int read_size = recv(sock, msg, 2000, 0);
  char *countPtr = strrchr(msg, ';');
  if (countPtr != NULL) {
    *countPtr = 0;
    countPtr++;
    *count = atoi(countPtr);
  }
  char *sizePtr = strrchr(msg, ';');
  if (sizePtr != NULL) {
    *sizePtr = 0;
    sizePtr++;
    *size = atoi(sizePtr);
  }
  if (0 == strcmp(msg, "receive")) {
    *mode = 1;
  }
  if (0 == strcmp(msg, "send")) {
    *mode = 2;
  }
  return read_size;
}


x86 assembly (clang, -O0):
<receiveModeMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
lea    -0x7f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x7f0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x7f4(%rbp)
lea    -0x7f0(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x800(%rbp)
cmpq   $0x0,-0x800(%rbp)
je     11f9 <receiveModeMsg+0xa9>
mov    -0x800(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x800(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x800(%rbp)
mov    -0x800(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x7f0(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x808(%rbp)
cmpq   $0x0,-0x808(%rbp)
je     124f <receiveModeMsg+0xff>
mov    -0x808(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x808(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x808(%rbp)
mov    -0x808(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x7f0(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    127a <receiveModeMsg+0x12a>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x7f0(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a5 <receiveModeMsg+0x155>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x7f4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveModeMsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%ebx
movl   $0xffffffff,(%rsi)
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
mov    $0x3b,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11bd <receiveModeMsg+0x6d>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,0x0(%r13)
mov    %rsp,%rdi
mov    $0x3b,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11e1 <receiveModeMsg+0x91>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r14)
lea    0xe18(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11fd <receiveModeMsg+0xad>
movl   $0x1,(%r12)
lea    0xe04(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1219 <receiveModeMsg+0xc9>
movl   $0x2,(%r12)
mov    %r15d,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"receive\00"
@.str.1 = [5 x i8] c"send\00"
define i32 @receiveModeMsg(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [2000 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%13 = load i32*, i32** %6
store i32 -1, i32* %13
%14 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 2000)
%16 = load i32, i32* %5
%17 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%18 = call i32 @recv(i32 %16, i8* %17, i32 2000, i32 0)
store i32 %18, i32* %10
%19 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%20 = call i8* @strrchr(i8* %19, i8 signext 59)
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %30
23: ; preds = %4
%24 = load i8*, i8** %11
store i8 0, i8* %24
%25 = load i8*, i8** %11
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %11
%27 = load i8*, i8** %11
%28 = call i32 @atoi(i8* %27)
%29 = load i32*, i32** %8
store i32 %28, i32* %29
br label %30
30: ; preds = %23, %4
%31 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%32 = call i8* @strrchr(i8* %31, i8 signext 59)
store i8* %32, i8** %12
%33 = load i8*, i8** %12
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i8*, i8** %12
store i8 0, i8* %36
%37 = load i8*, i8** %12
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %12
%39 = load i8*, i8** %12
%40 = call i32 @atoi(i8* %39)
%41 = load i32*, i32** %7
store i32 %40, i32* %41
br label %42
42: ; preds = %35, %30
%43 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%45 = icmp eq i64 0, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = load i32*, i32** %6
store i32 1, i32* %47
br label %48
48: ; preds = %46, %42
%49 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i64 0, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i32*, i32** %6
store i32 2, i32* %53
br label %54
54: ; preds = %52, %48
%55 = load i32, i32* %10
ret i32 %55
}

LLVM IR (-O2):
@.str = [8 x i8] c"receive\00"
@.str.1 = [5 x i8] c"send\00"
define i32 @receiveModeMsg(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [2000 x i8]
store i32 -1, i32* %1
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 2000)
%8 = call i32 @recv(i32 %0, i8* %6, i32 2000, i32 0)
%9 = call i8* @strrchr(i8* %6, i8 signext 59)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %4
store i8 0, i8* %9
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %3
br label %14
14: ; preds = %11, %4
%15 = call i8* @strrchr(i8* %6, i8 signext 59)
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
store i8 0, i8* %15
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %2
br label %20
20: ; preds = %17, %14
%21 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 1, i32* %1
br label %24
24: ; preds = %23, %20
%25 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 2, i32* %1
br label %28
28: ; preds = %27, %24
ret i32 %8
}