#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 {
  int tv_sec;
  unsigned int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, void *);
int timeout(struct timeval tv, int mseconds) {
  struct timeval tvx;
  unsigned int usec;
  gettimeofday(&(tvx), (void *)0);
  usec = (tvx.tv_sec - tv.tv_sec) * 1000000 + tvx.tv_usec - tv.tv_usec;
  return ((usec / 1000) >= mseconds);
}


x86 assembly (clang, -O0):
<timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
sub    -0x8(%rbp),%eax
imul   $0xf4240,%eax,%eax
add    -0x14(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
cmp    -0xc(%rbp),%eax
setae  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeout>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rdi,%rbx
shr    $0x20,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    %ebp,%eax
imul   $0xf4240,%eax,%eax
sub    %ebx,%ecx
add    %eax,%ecx
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
xor    %eax,%eax
cmp    %r14d,%ecx
setae  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @timeout(i64 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = bitcast %struct.timeval* %3 to i64*
store i64 %0, i64* %7
store i32 %1, i32* %4
%8 = call i32 @gettimeofday(%struct.timeval* %5, i8* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = mul nsw i32 %13, 1000000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%16 = load i32, i32* %15
%17 = add i32 %14, %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sub i32 %17, %19
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = udiv i32 %21, 1000
%23 = load i32, i32* %4
%24 = icmp uge i32 %22, %23
%25 = zext i1 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @timeout(i64 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = trunc i64 %0 to i32
%5 = lshr i64 %0, 32
%6 = trunc i64 %5 to i32
%7 = bitcast %struct.timeval* %3 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, i8* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %10, %4
%12 = mul nsw i32 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sub i32 %14, %6
%16 = add i32 %15, %12
%17 = udiv i32 %16, 1000
%18 = icmp uge i32 %17, %1
%19 = zext i1 %18 to i32
ret i32 %19
}