#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 */
struct timeval {
  unsigned int tv_sec;
  unsigned int tv_usec;
};
struct katcl_line {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_time_katcp(struct timeval *, struct timeval *,
                                  struct timeval *);
char *arg_string_katcl(struct katcl_line *, int);
int complete_rpc_katcl(struct katcl_line *, int /*<<< orphan*/,
                       struct timeval *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int await_reply_rpc_katcl(struct katcl_line *l, unsigned int timeout) {
  int result;
  struct timeval now, until, delta;
  char *ptr;
  delta.tv_sec = timeout / 1000;
  delta.tv_usec = (timeout % 1000) * 1000;
  gettimeofday(&now, NULL);
  add_time_katcp(&until, &now, &delta);
  while ((result = complete_rpc_katcl(l, 0, &until)) == 0)
    ;
  if (result < 0) {
    return -1;
  }
  ptr = arg_string_katcl(l, 1);
  if (ptr == NULL) {
    return -1;
  }
  if (strcmp(ptr, "ok")) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<await_reply_rpc_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <add_time_katcp@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x28(%rbp),%rdx
call   1070 <complete_rpc_katcl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11c1 <await_reply_rpc_katcl+0x71>
jmp    11a1 <await_reply_rpc_katcl+0x51>
cmpl   $0x0,-0x18(%rbp)
jge    11d7 <await_reply_rpc_katcl+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <await_reply_rpc_katcl+0xdd>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <arg_string_katcl@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1200 <await_reply_rpc_katcl+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <await_reply_rpc_katcl+0xdd>
mov    -0x38(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1226 <await_reply_rpc_katcl+0xd6>
movl   $0x1,-0x4(%rbp)
jmp    122d <await_reply_rpc_katcl+0xdd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<await_reply_rpc_katcl>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %esi,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,0x8(%rsp)
imul   $0x3e8,%eax,%eax
sub    %eax,%esi
imul   $0x3e8,%esi,%eax
mov    %eax,0xc(%rsp)
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <add_time_katcp@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1070 <complete_rpc_katcl@plt>
test   %eax,%eax
je     11b0 <await_reply_rpc_katcl+0x60>
mov    $0xffffffff,%ebp
js     11f2 <await_reply_rpc_katcl+0xa2>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <arg_string_katcl@plt>
test   %rax,%rax
je     11f2 <await_reply_rpc_katcl+0xa2>
lea    0xe1f(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"ok\00"
define i32 @await_reply_rpc_katcl(%struct.katcl_line* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.katcl_line*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i8*
store %struct.katcl_line* %0, %struct.katcl_line** %4
store i32 %1, i32* %5
%11 = load i32, i32* %5
%12 = udiv i32 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %5
%15 = urem i32 %14, 1000
%16 = mul i32 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%19 = call i32 @add_time_katcp(%struct.timeval* %8, %struct.timeval* %7, %struct.timeval* %9)
br label %20
20: ; preds = %24, %2
%21 = load %struct.katcl_line*, %struct.katcl_line** %4
%22 = call i32 @complete_rpc_katcl(%struct.katcl_line* %21, i32 0, %struct.timeval* %8)
store i32 %22, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %20
25: ; preds = %20
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 -1, i32* %3
br label %41
29: ; preds = %25
%30 = load %struct.katcl_line*, %struct.katcl_line** %4
%31 = call i8* @arg_string_katcl(%struct.katcl_line* %30, i32 1)
store i8* %31, i8** %10
%32 = load i8*, i8** %10
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 -1, i32* %3
br label %41
35: ; preds = %29
%36 = load i8*, i8** %10
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %3
br label %41
40: ; preds = %35
store i32 0, i32* %3
br label %41
41: ; preds = %40, %39, %34, %28
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"ok\00"
define i32 @await_reply_rpc_katcl(%struct.katcl_line* %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = udiv i32 %1, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 %9, i32* %10
%11 = urem i32 %1, 1000
%12 = mul nuw nsw i32 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%15 = call i32 @add_time_katcp(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %5)
br label %16
16: ; preds = %16, %2
%17 = call i32 @complete_rpc_katcl(%struct.katcl_line* %0, i32 0, %struct.timeval* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %16, label %19
19: ; preds = %16
%20 = icmp slt i32 %17, 0
br i1 %20, label %28, label %21
21: ; preds = %19
%22 = call i8* @arg_string_katcl(%struct.katcl_line* %0, i32 1)
%23 = icmp eq i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %24, %21, %19
%29 = phi i32 [ -1, %19 ], [ -1, %21 ], [ %27, %24 ]
ret i32 %29
}