#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 struct timeval {
  int tv_sec;
  int tv_usec;
} const timeval;

/* Variables and functions */
int errno;
int /*<<< orphan*/ gettimeofday(struct timeval const *, void *);
int /*<<< orphan*/ timeval_subtract(struct timeval const *,
                                    struct timeval const *,
                                    struct timeval const *);
void vbi_capture_io_update_timeout(struct timeval *timeout,
                                   const struct timeval *tv_start) {
  struct timeval delta;
  struct timeval tv_stop;
  int errno_saved;
  errno_saved = errno;
  gettimeofday(&tv_stop, ((void *)0));
  errno = errno_saved;
  timeval_subtract(&delta, &tv_stop, tv_start);
  if ((delta.tv_sec | delta.tv_usec) < 0) {
    delta.tv_sec = 0;
    delta.tv_usec = 0;
  } else {
    timeval_subtract(timeout, timeout, &delta);
    if ((timeout->tv_sec | timeout->tv_usec) < 0) {
      timeout->tv_sec = 0;
      timeout->tv_usec = 0;
    }
  }
}


x86 assembly (clang, -O0):
<vbi_capture_io_update_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x24(%rbp),%ecx
mov    0x2e8d(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <timeval_subtract@plt>
mov    -0x18(%rbp),%eax
or     -0x14(%rbp),%eax
cmp    $0x0,%eax
jge    1188 <vbi_capture_io_update_timeout+0x68>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    11c9 <vbi_capture_io_update_timeout+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <timeval_subtract@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
or     0x4(%rcx),%eax
cmp    $0x0,%eax
jge    11c4 <vbi_capture_io_update_timeout+0xa4>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x4(%rax)
jmp    11c9 <vbi_capture_io_update_timeout+0xa9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vbi_capture_io_update_timeout>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea7(%rip),%r12
mov    (%r12),%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %ebp,(%r12)
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <timeval_subtract@plt>
mov    0x4(%rsp),%eax
or     (%rsp),%eax
js     1183 <vbi_capture_io_update_timeout+0x63>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <timeval_subtract@plt>
mov    0x4(%rbx),%eax
or     (%rbx),%eax
jns    1183 <vbi_capture_io_update_timeout+0x63>
movq   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@errno = global i32 0
define void @vbi_capture_io_update_timeout(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%8 = load i32, i32* @errno
store i32 %8, i32* %7
%9 = call i32 @gettimeofday(%struct.timeval* %6, i8* null)
%10 = load i32, i32* %7
store i32 %10, i32* @errno
%11 = load %struct.timeval*, %struct.timeval** %4
%12 = call i32 @timeval_subtract(%struct.timeval* %5, %struct.timeval* %6, %struct.timeval* %11)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%16 = load i32, i32* %15
%17 = or i32 %14, %16
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 0, i32* %21
br label %40
22: ; preds = %2
%23 = load %struct.timeval*, %struct.timeval** %3
%24 = load %struct.timeval*, %struct.timeval** %3
%25 = call i32 @timeval_subtract(%struct.timeval* %23, %struct.timeval* %24, %struct.timeval* %5)
%26 = load %struct.timeval*, %struct.timeval** %3
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load %struct.timeval*, %struct.timeval** %3
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = or i32 %28, %31
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %22
%35 = load %struct.timeval*, %struct.timeval** %3
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
store i32 0, i32* %36
%37 = load %struct.timeval*, %struct.timeval** %3
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %37, i32 0, i32 1
store i32 0, i32* %38
br label %39
39: ; preds = %34, %22
br label %40
40: ; preds = %39, %19
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@errno = global i32 0
define void @vbi_capture_io_update_timeout(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = load i32, i32* @errno
%8 = call i32 @gettimeofday(%struct.timeval* %4, i8* null)
store i32 %7, i32* @errno
%9 = call i32 @timeval_subtract(%struct.timeval* %3, %struct.timeval* %4, %struct.timeval* %1)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = or i32 %13, %11
%15 = icmp slt i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %2
%17 = call i32 @timeval_subtract(%struct.timeval* %0, %struct.timeval* %0, %struct.timeval* %3)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%21 = load i32, i32* %20
%22 = or i32 %21, %19
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 0, i32* %18
store i32 0, i32* %20
br label %25
25: ; preds = %2, %16, %24
ret void
}