#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 htonl(int);
int ntohl(int);
scalar_t__ read(int, int *, int);
scalar_t__ write(int, int *, int);
int negotiate_test_cycle_time(int sockfd, int proposed_time) {
  int converted = htonl(proposed_time);
  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;
  }
  return ntohl(response);
}


x86 assembly (clang, -O0):
<negotiate_test_cycle_time>:
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    11a3 <negotiate_test_cycle_time+0x53>
lea    0xe6e(%rip),%rdi
call   1070 <PRINT_ERR@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <negotiate_test_cycle_time+0x91>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jg     11d6 <negotiate_test_cycle_time+0x86>
lea    0xe74(%rip),%rdi
call   1070 <PRINT_ERR@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <negotiate_test_cycle_time+0x91>
mov    -0x14(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<negotiate_test_cycle_time>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %rax,%rax
js     11a4 <negotiate_test_cycle_time+0x54>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11ad <negotiate_test_cycle_time+0x5d>
mov    0x8(%rsp),%edi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <ntohl@plt>
lea    0xe55(%rip),%rdi
jmp    11b4 <negotiate_test_cycle_time+0x64>
lea    0xe85(%rip),%rdi
call   1070 <PRINT_ERR@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
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"
define i32 @negotiate_test_cycle_time(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 %24
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 %24
21: ; preds = %15
%22 = load i32, i32* %7
%23 = call i32 @ntohl(i32 %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %19, %13
%25 = load i32, i32* %3
ret i32 %25
}

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"
define i32 @negotiate_test_cycle_time(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 %10, label %12
10: ; preds = %2
%11 = tail call i32 @PRINT_ERR(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %20
12: ; preds = %2
%13 = call i64 @read(i32 %0, i32* %4, i32 4)
%14 = icmp slt i64 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @PRINT_ERR(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = tail call i32 @ntohl(i32 %18)
br label %20
20: ; preds = %17, %15, %10
%21 = phi i32 [ -1, %10 ], [ -1, %15 ], [ %19, %17 ]
ret i32 %21
}