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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, long);
int get_timeout(struct timeval start, struct timeval *timeout) {
  struct timeval current;
  gettimeofday(&current, NULL);
  long diff;
  diff = (current.tv_sec - start.tv_sec) * 1000000 +
         (current.tv_usec - start.tv_usec);
  long timeout_l = 50000 - diff;
  if (timeout_l < 0) {
    timeout->tv_sec = 0;
    timeout->tv_usec = 0;
  } else {
    timeout->tv_sec = timeout_l / 1000000;
    timeout->tv_usec = timeout_l;
  }
  printf("Timeout: %d:%d\n", timeout->tv_sec, timeout->tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<get_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
sub    -0x8(%rbp),%eax
imul   $0xf4240,%eax,%eax
mov    -0x14(%rbp),%ecx
sub    -0x4(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    $0xc350,%eax
sub    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1189 <get_timeout+0x69>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
jmp    11ac <get_timeout+0x8c>
mov    -0x28(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rsi
mov    -0x10(%rbp),%rax
movslq 0x4(%rax),%rdx
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timeout>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdi,%rbx
shr    $0x20,%rbx
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    %r12d,%eax
imul   $0xf4240,%eax,%eax
sub    %ebx,%ecx
add    %eax,%ecx
movslq %ecx,%rsi
mov    $0xc350,%ecx
sub    %rsi,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x12,%rdx
add    %eax,%edx
cmp    $0xc351,%esi
cmovge %r15d,%edx
cmovge %r15d,%ecx
mov    %edx,(%r14)
mov    %ecx,0x4(%r14)
movslq %edx,%rsi
movslq %ecx,%rdx
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [16 x i8] c"Timeout: %d:%d\0A\00"
define i32 @get_timeout(i64 %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = alloca i64
%8 = bitcast %struct.timeval* %3 to i64*
store i64 %0, i64* %8
store %struct.timeval* %1, %struct.timeval** %4
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sub nsw i32 %11, %13
%15 = mul nsw i32 %14, 1000000
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sub nsw i32 %17, %19
%21 = add nsw i32 %15, %20
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = sub nsw i64 50000, %23
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = load %struct.timeval*, %struct.timeval** %4
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
store i32 0, i32* %29
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 1
store i32 0, i32* %31
br label %42
32: ; preds = %2
%33 = load i64, i64* %7
%34 = sdiv i64 %33, 1000000
%35 = trunc i64 %34 to i32
%36 = load %struct.timeval*, %struct.timeval** %4
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i64, i64* %7
%39 = trunc i64 %38 to i32
%40 = load %struct.timeval*, %struct.timeval** %4
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 1
store i32 %39, i32* %41
br label %42
42: ; preds = %32, %27
%43 = load %struct.timeval*, %struct.timeval** %4
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = load %struct.timeval*, %struct.timeval** %4
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = sext i32 %49 to i64
%51 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %46, i64 %50)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [16 x i8] c"Timeout: %d:%d\0A\00"
define i32 @get_timeout(i64 %0, %struct.timeval* nocapture %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, i32* 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 nsw i32 %14, %6
%16 = add nsw i32 %12, %15
%17 = sext i32 %16 to i64
%18 = sub nsw i64 50000, %17
%19 = icmp sgt i32 %16, 50000
%20 = sdiv i64 %18, 1000000
%21 = trunc i64 %20 to i32
%22 = trunc i64 %18 to i32
%23 = select i1 %19, i32 0, i32 %21
%24 = select i1 %19, i32 0, i32 %22
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 %23, i32* %25
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i32 %24, i32* %26
%27 = sext i32 %23 to i64
%28 = sext i32 %24 to i64
%29 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %27, i64 %28)
ret i32 0
}