#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 */
char read_msg_id(int);
int /*<<< orphan*/ read_param(int, char *, int);
int read_msg(int socket, char msg_id, char *buf, int len) {
  char *param_ptr = NULL;
  char c;
  c = read_msg_id(socket);
  if (c < 0) {
    return -1;
  }
  while (c != msg_id) {
    read_param(socket, buf, len);
    c = read_msg_id(socket);
  }
  read_param(socket, buf, len);
}


x86 assembly (clang, -O0):
<read_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <read_msg_id@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jge    1164 <read_msg+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <read_msg+0x87>
jmp    1169 <read_msg+0x49>
movsbl -0x29(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     1198 <read_msg+0x78>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <read_param@plt>
mov    -0x8(%rbp),%edi
call   1040 <read_msg_id@plt>
mov    %al,-0x29(%rbp)
jmp    1169 <read_msg+0x49>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <read_param@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <read_msg_id@plt>
test   %al,%al
js     1169 <read_msg+0x49>
nopw   0x0(%rax,%rax,1)
cmp    %bl,%al
je     115c <read_msg+0x3c>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <read_param@plt>
mov    %ebp,%edi
call   1040 <read_msg_id@plt>
cmp    %bl,%al
jne    1144 <read_msg+0x24>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <read_param@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_msg(i32 %0, i8 signext %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* null, i8** %10
%12 = load i32, i32* %6
%13 = call signext i8 @read_msg_id(i32 %12)
store i8 %13, i8* %11
%14 = load i8, i8* %11
%15 = sext i8 %14 to i32
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %37
18: ; preds = %4
br label %19
19: ; preds = %25, %18
%20 = load i8, i8* %11
%21 = sext i8 %20 to i32
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = call i32 @read_param(i32 %26, i8* %27, i32 %28)
%30 = load i32, i32* %6
%31 = call signext i8 @read_msg_id(i32 %30)
store i8 %31, i8* %11
br label %19
32: ; preds = %19
%33 = load i32, i32* %6
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = call i32 @read_param(i32 %33, i8* %34, i32 %35)
br label %37
37: ; preds = %32, %17
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @read_msg(i32 %0, i8 signext %1, i8* %2, i32 %3) {
%5 = tail call signext i8 @read_msg_id(i32 %0)
%6 = icmp slt i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = icmp eq i8 %5, %1
br i1 %8, label %13, label %9
9: ; preds = %7, %9
%10 = tail call i32 @read_param(i32 %0, i8* %2, i32 %3)
%11 = tail call signext i8 @read_msg_id(i32 %0)
%12 = icmp eq i8 %11, %1
br i1 %12, label %13, label %9
13: ; preds = %9, %7
%14 = tail call i32 @read_param(i32 %0, i8* %2, i32 %3)
br label %15
15: ; preds = %4, %13
ret i32 -1
}