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

/* Variables and functions */
struct timeval tvCreate(long seconds, long microseconds) {
  struct timeval result;
  seconds = (seconds < 0) ? 0 : seconds;
  microseconds = (microseconds < 0) ? 0 : microseconds;
  while (microseconds >= 1000000L) {
    seconds++;
    microseconds = microseconds - 1000000L;
  }
  result.tv_sec = seconds;
  result.tv_usec = microseconds;
  return (result);
}


x86 assembly (clang, -O0):
<tvCreate>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1122 <tvCreate+0x22>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    112a <tvCreate+0x2a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1148 <tvCreate+0x48>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1150 <tvCreate+0x50>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
jl     1185 <tvCreate+0x85>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <tvCreate+0x58>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvCreate>:
xor    %ecx,%ecx
test   %rdi,%rdi
cmovs  %rcx,%rdi
test   %rsi,%rsi
cmovns %rsi,%rcx
cmp    $0xf4240,%rcx
jb     115e <tvCreate+0x5e>
cmp    $0x1e847f,%rcx
mov    $0x1e847f,%eax
cmovl  %rcx,%rax
neg    %rax
add    %rcx,%rax
add    $0xf423f,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mul    %rdx
shr    $0x12,%rdx
add    %rdx,%rdi
add    $0x1,%rdi
imul   $0xfffffffffff0bdc0,%rdx,%rax
add    %rax,%rcx
add    $0xfffffffffff0bdc0,%rcx
mov    %rdi,%rax
mov    %rcx,%rdx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @tvCreate(i64 %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %11
9: ; preds = %2
%10 = load i64, i64* %4
br label %11
11: ; preds = %9, %8
%12 = phi i64 [ 0, %8 ], [ %10, %9 ]
store i64 %12, i64* %4
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %18
16: ; preds = %11
%17 = load i64, i64* %5
br label %18
18: ; preds = %16, %15
%19 = phi i64 [ 0, %15 ], [ %17, %16 ]
store i64 %19, i64* %5
br label %20
20: ; preds = %23, %18
%21 = load i64, i64* %5
%22 = icmp sge i64 %21, 1000000
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 1
store i64 %25, i64* %4
%26 = load i64, i64* %5
%27 = sub nsw i64 %26, 1000000
store i64 %27, i64* %5
br label %20
28: ; preds = %20
%29 = load i64, i64* %4
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i64 %29, i64* %30
%31 = load i64, i64* %5
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 %31, i64* %32
%33 = bitcast %struct.timeval* %3 to { i64, i64 }*
%34 = load { i64, i64 }, { i64, i64 }* %33
ret { i64, i64 } %34
}

LLVM IR (-O2):
define { i64, i64 } @tvCreate(i64 %0, i64 %1) {
%3 = icmp sgt i64 %0, 0
%4 = select i1 %3, i64 %0, i64 0
%5 = icmp sgt i64 %1, 0
%6 = select i1 %5, i64 %1, i64 0
%7 = icmp ugt i64 %6, 999999
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = add nuw i64 %6, 999999
%10 = call i64 @llvm.smin.i64(i64 %6, i64 1999999)
%11 = sub nuw i64 %9, %10
%12 = udiv i64 %11, 1000000
%13 = add nuw i64 %4, %12
%14 = add nuw i64 %13, 1
%15 = mul nsw i64 %12, -1000000
%16 = add nsw i64 %6, -1000000
%17 = add nsw i64 %15, %16
br label %18
18: ; preds = %8, %2
%19 = phi i64 [ %4, %2 ], [ %14, %8 ]
%20 = phi i64 [ %6, %2 ], [ %17, %8 ]
%21 = insertvalue { i64, i64 } poison, i64 %19, 0
%22 = insertvalue { i64, i64 } %21, i64 %20, 1
ret { i64, i64 } %22
}