#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*/ tv;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct timeval *, int);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int try(int s, int seconds) {
  fprintf(stderr, "Trying with timeout %d seconds...", seconds);
  struct timeval tv;
  tv.tv_sec = seconds + 2;
  tv.tv_usec = 0;
  setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  char buf[128];
  int l;
  l = snprintf(buf, sizeof(buf), "0 0 %d 0\n", seconds);
  l = send(s, buf, l, 0);
  if (l == -1) {
    perror("send");
    return -1;
  }
  l = recv(s, buf, sizeof(buf), 0);
  if (l < 1) {
    fprintf(stderr, "Fail B...\n");
    return -1;
  }
  if (buf[0] != 'B') {
    fprintf(stderr, "Strange B\n");
    return -1;
  }
  l = recv(s, buf, sizeof(buf), 0);
  if (l < 1) {
    fprintf(stderr, "FAIL\n");
    return -1;
  }
  if (buf[0] != 'A') {
    fprintf(stderr, "Strange A\n");
    return -1;
  }
  fprintf(stderr, "OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<try>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x80,%esi
lea    0xe4c(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0xa4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa4(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    1223 <try+0xc3>
lea    0xe1a(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <try+0x1df>
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x1,-0xa4(%rbp)
jge    126f <try+0x10f>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <try+0x1df>
movsbl -0xa0(%rbp),%eax
cmp    $0x42,%eax
je     12a2 <try+0x142>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <try+0x1df>
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x1,-0xa4(%rbp)
jge    12ee <try+0x18e>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <try+0x1df>
movsbl -0xa0(%rbp),%eax
cmp    $0x41,%eax
je     1321 <try+0x1c1>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <try+0x1df>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x2e57(%rip),%r15
mov    (%r15),%edi
lea    0xe7d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x2(%rbx),%eax
mov    %eax,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %r14d,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
lea    0xe5d(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
call   1060 <snprintf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
je     128b <try+0x12b>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1244 <try+0xe4>
cmpb   $0x42,0x10(%rsp)
jne    1250 <try+0xf0>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    125c <try+0xfc>
cmpb   $0x41,0x10(%rsp)
mov    (%r15),%edi
jne    1268 <try+0x108>
lea    0xe1f(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    127b <try+0x11b>
mov    (%r15),%edi
lea    0xde3(%rip),%rsi
jmp    126f <try+0x10f>
mov    (%r15),%edi
lea    0xde2(%rip),%rsi
jmp    126f <try+0x10f>
mov    (%r15),%edi
lea    0xde1(%rip),%rsi
jmp    126f <try+0x10f>
lea    0xdde(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9a(%rip),%rdi
call   1080 <perror@plt>
jmp    1276 <try+0x116>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [34 x i8] c"Trying with timeout %d seconds...\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.1 = [10 x i8] c"0 0 %d 0\0A\00"
@.str.2 = [5 x i8] c"send\00"
@.str.3 = [11 x i8] c"Fail B...\0A\00"
@.str.4 = [11 x i8] c"Strange B\0A\00"
@.str.5 = [6 x i8] c"FAIL\0A\00"
@.str.6 = [11 x i8] c"Strange A\0A\00"
@.str.7 = [4 x i8] c"OK\0A\00"
define i32 @try(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca [128 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* @stderr
%10 = load i32, i32* %5
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i64 0, i64* %15
%16 = load i32, i32* %4
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_RCVTIMEO
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, %struct.timeval* %6, i32 16)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 @snprintf(i8* %20, i32 128, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %4
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %8
%26 = call i32 @send(i32 %23, i8* %24, i32 %25, i32 0)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
31: ; preds = %2
%32 = load i32, i32* %4
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%34 = call i32 @recv(i32 %32, i8* %33, i32 128, i32 0)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
40: ; preds = %31
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 66
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
48: ; preds = %40
%49 = load i32, i32* %4
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%51 = call i32 @recv(i32 %49, i8* %50, i32 128, i32 0)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp slt i32 %52, 1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
57: ; preds = %48
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 65
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
65: ; preds = %57
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %68
68: ; preds = %65, %62, %54, %45, %37, %29
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [34 x i8] c"Trying with timeout %d seconds...\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.1 = [10 x i8] c"0 0 %d 0\0A\00"
@.str.2 = [5 x i8] c"send\00"
@.str.3 = [11 x i8] c"Fail B...\0A\00"
@.str.4 = [11 x i8] c"Strange B\0A\00"
@.str.5 = [6 x i8] c"FAIL\0A\00"
@.str.6 = [11 x i8] c"Strange A\0A\00"
@.str.7 = [4 x i8] c"OK\0A\00"
define i32 @try(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca [128 x i8]
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = bitcast %struct.timeval* %3 to i8*
%8 = add nsw i32 %1, 2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %10
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_RCVTIMEO
%13 = call i32 @setsockopt(i32 %0, i32 %11, i32 %12, %struct.timeval* %3, i32 16)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%15 = call i32 @snprintf(i8* %14, i32 128, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%16 = call i32 @send(i32 %0, i8* %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %46
20: ; preds = %2
%21 = call i32 @recv(i32 %0, i8* %14, i32 128, i32 0)
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %46
26: ; preds = %20
%27 = load i8, i8* %14
%28 = icmp eq i8 %27, 66
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %46
32: ; preds = %26
%33 = call i32 @recv(i32 %0, i8* %14, i32 128, i32 0)
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %46
38: ; preds = %32
%39 = load i8, i8* %14
%40 = icmp eq i8 %39, 65
%41 = load i32, i32* @stderr
br i1 %40, label %44, label %42
42: ; preds = %38
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %46
44: ; preds = %38
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %42, %35, %29, %23, %18
%47 = phi i32 [ -1, %18 ], [ -1, %23 ], [ -1, %29 ], [ -1, %35 ], [ -1, %42 ], [ 0, %44 ]
ret i32 %47
}