#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 TCPIPMsgRecv(int, int *, int);
int TCPIPMsgSend(int, ...);
int RMsgSndOpen(int sock, size_t buflen, unsigned char *bufadr) {
  int s;
  int msg = 'O';
  s = TCPIPMsgSend(sock, &msg, sizeof(int));
  if (s != sizeof(int))
    return -1;
  s = TCPIPMsgSend(sock, &buflen, sizeof(size_t));
  if (s != sizeof(size_t))
    return -1;
  s = TCPIPMsgSend(sock, bufadr, buflen);
  if (s != buflen)
    return -1;
  s = TCPIPMsgRecv(sock, &msg, sizeof(int));
  if (s != sizeof(int))
    return -1;
  if (msg != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<RMsgSndOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4f,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <TCPIPMsgSend@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x4,%rax
je     116a <RMsgSndOpen+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <RMsgSndOpen+0xf4>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <TCPIPMsgSend@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x8,%rax
je     119a <RMsgSndOpen+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <RMsgSndOpen+0xf4>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <TCPIPMsgSend@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c9 <RMsgSndOpen+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <RMsgSndOpen+0xf4>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <TCPIPMsgRecv@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x4,%rax
je     11f7 <RMsgSndOpen+0xd7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <RMsgSndOpen+0xf4>
cmpl   $0x0,-0x20(%rbp)
je     120d <RMsgSndOpen+0xed>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <RMsgSndOpen+0xf4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RMsgSndOpen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %edi,%ebp
mov    %rsi,0x8(%rsp)
movl   $0x4f,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <TCPIPMsgSend@plt>
mov    $0xffffffff,%ebx
cmp    $0x4,%eax
jne    11a5 <RMsgSndOpen+0x85>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <TCPIPMsgSend@plt>
cmp    $0x8,%eax
jne    11a5 <RMsgSndOpen+0x85>
mov    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <TCPIPMsgSend@plt>
cltq
cmp    %rax,0x8(%rsp)
jne    11a5 <RMsgSndOpen+0x85>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1040 <TCPIPMsgRecv@plt>
cmp    $0x4,%eax
jne    11a5 <RMsgSndOpen+0x85>
xor    %eax,%eax
cmp    0x4(%rsp),%eax
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @RMsgSndOpen(i32 %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 79, i32* %9
%10 = load i32, i32* %5
%11 = call i32 (i32, ...) @TCPIPMsgSend(i32 %10, i32* %9, i64 4)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 4
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %45
16: ; preds = %3
%17 = load i32, i32* %5
%18 = call i32 (i32, ...) @TCPIPMsgSend(i32 %17, i64* %6, i64 8)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = icmp ne i64 %20, 8
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %4
br label %45
23: ; preds = %16
%24 = load i32, i32* %5
%25 = load i8*, i8** %7
%26 = load i64, i64* %6
%27 = call i32 (i32, ...) @TCPIPMsgSend(i32 %24, i8* %25, i64 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = load i64, i64* %6
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 -1, i32* %4
br label %45
33: ; preds = %23
%34 = load i32, i32* %5
%35 = call i32 @TCPIPMsgRecv(i32 %34, i32* %9, i32 4)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = icmp ne i64 %37, 4
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 -1, i32* %4
br label %45
40: ; preds = %33
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 -1, i32* %4
br label %45
44: ; preds = %40
store i32 0, i32* %4
br label %45
45: ; preds = %44, %43, %39, %32, %22, %15
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
define i32 @RMsgSndOpen(i32 %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
store i64 %1, i64* %4
%6 = bitcast i32* %5 to i8*
store i32 79, i32* %5
%7 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i32* %5, i64 4)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i64* %4, i64 8)
%11 = icmp eq i32 %10, 8
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i64, i64* %4
%14 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i8* %2, i64 %13)
%15 = sext i32 %14 to i64
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, %15
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = call i32 @TCPIPMsgRecv(i32 %0, i32* %5, i32 4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
%24 = sext i1 %23 to i32
br label %25
25: ; preds = %21, %18, %12, %9, %3
%26 = phi i32 [ -1, %3 ], [ -1, %9 ], [ -1, %12 ], [ -1, %18 ], [ %24, %21 ]
ret i32 %26
}