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

/* Variables and functions */
int /*<<< orphan*/ PRINT_ERR(char *);
int /*<<< orphan*/ PRINT_INFO(char *);
int htonl(int);
int ntohl(int);
scalar_t__ read(int, int *, int);
scalar_t__ write(int, int *, int);
int request_to_start(int sockfd, int request) {
  int converted = htonl(request);
  int response = 0;
  if (write(sockfd, &converted, sizeof(converted)) < 0) {
    PRINT_ERR("cannot write data to the socket for sender/receiver sync");
    return -1;
  }
  if (read(sockfd, &response, sizeof(response)) <= 0) {
    PRINT_ERR("cannot read data from the socket for sender/receiver sync");
    return -1;
  }
  if (ntohl(response) == (int)'W') {
    PRINT_INFO("waiting for the last client to join the test");
    if (read(sockfd, &response, sizeof(response)) <= 0) {
      PRINT_ERR("cannot read data from the socket for sender/receiver sync");
      return -1;
    }
  }
  if (ntohl(response) != (int)'R') {
    PRINT_ERR("receiver is not ready to run test with this sender");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<request_to_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b3 <request_to_start+0x53>
lea    0xe5e(%rip),%rdi
call   1080 <PRINT_ERR@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <request_to_start+0x10b>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jg     11e6 <request_to_start+0x86>
lea    0xe64(%rip),%rdi
call   1080 <PRINT_ERR@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <request_to_start+0x10b>
mov    -0x14(%rbp),%edi
call   1070 <ntohl@plt>
cmp    $0x57,%eax
jne    123b <request_to_start+0xdb>
lea    0xe75(%rip),%rdi
call   1060 <PRINT_INFO@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jg     1236 <request_to_start+0xd6>
lea    0xe14(%rip),%rdi
call   1080 <PRINT_ERR@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <request_to_start+0x10b>
jmp    123b <request_to_start+0xdb>
mov    -0x14(%rbp),%edi
call   1070 <ntohl@plt>
cmp    $0x52,%eax
je     1264 <request_to_start+0x104>
lea    0xe4d(%rip),%rdi
call   1080 <PRINT_ERR@plt>
movl   $0x0,-0x4(%rbp)
jmp    126b <request_to_start+0x10b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_to_start>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,%edi
call   1040 <htonl@plt>
mov    %eax,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1202 <request_to_start+0xa2>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
lea    0xe8c(%rip),%r15
test   %rax,%rax
jle    1209 <request_to_start+0xa9>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1070 <ntohl@plt>
cmp    $0x57,%eax
jne    11e4 <request_to_start+0x84>
lea    0xeab(%rip),%rdi
call   1060 <PRINT_INFO@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    1209 <request_to_start+0xa9>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1070 <ntohl@plt>
mov    $0x1,%r14d
cmp    $0x52,%eax
je     1211 <request_to_start+0xb1>
xor    %r14d,%r14d
lea    0xea0(%rip),%r15
jmp    1209 <request_to_start+0xa9>
lea    0xdf7(%rip),%r15
mov    %r15,%rdi
call   1080 <PRINT_ERR@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"cannot write data to the socket for sender/receiver sync\00"
@.str.1 = [58 x i8] c"cannot read data from the socket for sender/receiver sync\00"
@.str.2 = [45 x i8] c"waiting for the last client to join the test\00"
@.str.3 = [51 x i8] c"receiver is not ready to run test with this sender\00"
define i32 @request_to_start(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = call i32 @htonl(i32 %8)
store i32 %9, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = call i64 @write(i32 %10, i32* %6, i32 4)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @PRINT_ERR(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
15: ; preds = %2
%16 = load i32, i32* %4
%17 = call i64 @read(i32 %16, i32* %7, i32 4)
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @PRINT_ERR(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
21: ; preds = %15
%22 = load i32, i32* %7
%23 = call i32 @ntohl(i32 %22)
%24 = icmp eq i32 %23, 87
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = call i32 @PRINT_INFO(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %4
%28 = call i64 @read(i32 %27, i32* %7, i32 4)
%29 = icmp sle i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @PRINT_ERR(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
32: ; preds = %25
br label %33
33: ; preds = %32, %21
%34 = load i32, i32* %7
%35 = call i32 @ntohl(i32 %34)
%36 = icmp ne i32 %35, 82
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @PRINT_ERR(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %40
39: ; preds = %33
store i32 1, i32* %3
br label %40
40: ; preds = %39, %37, %30, %19, %13
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [57 x i8] c"cannot write data to the socket for sender/receiver sync\00"
@.str.1 = [58 x i8] c"cannot read data from the socket for sender/receiver sync\00"
@.str.2 = [45 x i8] c"waiting for the last client to join the test\00"
@.str.3 = [51 x i8] c"receiver is not ready to run test with this sender\00"
define i32 @request_to_start(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @htonl(i32 %1)
store i32 %6, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = call i64 @write(i32 %0, i32* %3, i32 4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %2
%11 = call i64 @read(i32 %0, i32* %4, i32 4)
%12 = icmp slt i64 %11, 1
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = load i32, i32* %4
%15 = tail call i32 @ntohl(i32 %14)
%16 = icmp eq i32 %15, 87
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = tail call i32 @PRINT_INFO(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%19 = call i64 @read(i32 %0, i32* %4, i32 4)
%20 = icmp slt i64 %19, 1
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = load i32, i32* %4
br label %23
23: ; preds = %21, %13
%24 = phi i32 [ %22, %21 ], [ %14, %13 ]
%25 = tail call i32 @ntohl(i32 %24)
%26 = icmp eq i32 %25, 82
br i1 %26, label %31, label %27
27: ; preds = %23, %17, %10, %2
%28 = phi i8* [ getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), %23 ]
%29 = phi i32 [ -1, %2 ], [ -1, %10 ], [ -1, %17 ], [ 0, %23 ]
%30 = tail call i32 @PRINT_ERR(i8* %28)
br label %31
31: ; preds = %27, %23
%32 = phi i32 [ 1, %23 ], [ %29, %27 ]
ret i32 %32
}