#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 *, int);
int RMsgSndClose(int sock) {
  int s;
  int msg = 'C';
  s = TCPIPMsgSend(sock, &msg, sizeof(int));
  if (s != sizeof(int))
    return -1;
  s = TCPIPMsgRecv(sock, &msg, sizeof(int));
  if (s != sizeof(int))
    return s;
  if (msg != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<RMsgSndClose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x43,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <TCPIPMsgSend@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
je     1160 <RMsgSndClose+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <RMsgSndClose+0x8a>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
je     118d <RMsgSndClose+0x6d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <RMsgSndClose+0x8a>
cmpl   $0x0,-0x10(%rbp)
je     11a3 <RMsgSndClose+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <RMsgSndClose+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RMsgSndClose>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x43,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <TCPIPMsgSend@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jne    1168 <RMsgSndClose+0x48>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <TCPIPMsgRecv@plt>
cmp    $0x4,%eax
jne    1168 <RMsgSndClose+0x48>
xor    %eax,%eax
cmp    0xc(%rsp),%eax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @RMsgSndClose(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 67, i32* %2
%4 = call i32 @TCPIPMsgSend(i32 %0, i32* %2, i32 4)
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = call i32 @TCPIPMsgRecv(i32 %0, i32* %2, i32 4)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %9, %6, %1
%14 = phi i32 [ -1, %1 ], [ %7, %6 ], [ %12, %9 ]
ret i32 %14
}