#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 random();
void timeval_min_sec(struct timeval *d, int secs) {
  if (d->tv_sec == 0 || d->tv_sec > secs) {
    d->tv_sec = secs;
    d->tv_usec = random() % 1000000;
  }
}


x86 assembly (clang, -O0):
<timeval_min_sec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
je     113b <timeval_min_sec+0x2b>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jle    115a <timeval_min_sec+0x4a>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,0x4(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_min_sec>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%eax
test   %eax,%eax
je     1120 <timeval_min_sec+0x10>
cmp    %esi,%eax
jg     1120 <timeval_min_sec+0x10>
pop    %rbx
ret
mov    %esi,(%rbx)
xor    %eax,%eax
call   1030 <random@plt>
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @timeval_min_sec(%struct.timeval* %0, i32 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store i32 %1, i32* %4
%5 = load %struct.timeval*, %struct.timeval** %3
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* %4
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %9, %2
%16 = load i32, i32* %4
%17 = load %struct.timeval*, %struct.timeval** %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 (...) @random()
%20 = srem i32 %19, 1000000
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
store i32 %20, i32* %22
br label %23
23: ; preds = %15, %9
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @timeval_min_sec(%struct.timeval* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
%6 = icmp sgt i32 %4, %1
%7 = or i1 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %2
store i32 %1, i32* %3
%9 = tail call i32 (...) @random()
%10 = srem i32 %9, 1000000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %10, i32* %11
br label %12
12: ; preds = %2, %8
ret void
}