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

/* Variables and functions */
int random();
void timeval_min_sec(struct timeval *d, time_t 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    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     113f <timeval_min_sec+0x2f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jle    1160 <timeval_min_sec+0x50>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_min_sec>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rax
test   %rax,%rax
je     1123 <timeval_min_sec+0x13>
cmp    %rsi,%rax
jg     1123 <timeval_min_sec+0x13>
pop    %rbx
ret
mov    %rsi,(%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,0x8(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define void @timeval_min_sec(%struct.timeval* %0, i64 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store i64 %1, i64* %4
%5 = load %struct.timeval*, %struct.timeval** %3
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%7 = load i64, i64* %6
%8 = icmp eq i64 %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 i64, i64* %11
%13 = load i64, i64* %4
%14 = icmp sgt i64 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %9, %2
%16 = load i64, i64* %4
%17 = load %struct.timeval*, %struct.timeval** %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i64 %16, i64* %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 { i64, i32 }
define void @timeval_min_sec(%struct.timeval* nocapture %0, i64 %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = icmp eq i64 %4, 0
%6 = icmp sgt i64 %4, %1
%7 = or i1 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %2
store i64 %1, i64* %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
}