#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct timeval {
  scalar_t__ tv_sec;
  int tv_usec;
};
struct TYPE_3__ {
  int quot;
};
typedef TYPE_1__ ldiv_t;

/* Variables and functions */
int /*<<< orphan*/ inter_maxto(struct timeval **, struct timeval *,
                               struct timeval);
TYPE_1__ ldiv(int, int);
int /*<<< orphan*/ timerclear(struct timeval *);
void inter_maxtoabs(struct timeval **tv_io, struct timeval *tvbuf,
                    struct timeval now, struct timeval maxtime) {
  ldiv_t dr;
  if (!tv_io)
    return;
  maxtime.tv_sec -= (now.tv_sec + 2);
  maxtime.tv_usec -= (now.tv_usec - 2000000);
  dr = ldiv(maxtime.tv_usec, 1000000);
  maxtime.tv_sec += dr.quot;
  maxtime.tv_usec -= dr.quot * 1000000;
  if (maxtime.tv_sec < 0)
    timerclear(&maxtime);
  inter_maxto(tv_io, tvbuf, maxtime);
}


x86 assembly (clang, -O0):
<inter_maxtoabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x8(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x18(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115f <inter_maxtoabs+0x2f>
jmp    11dc <inter_maxtoabs+0xac>
mov    -0x10(%rbp),%rcx
add    $0x2,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1e8480,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    $0xf4240,%esi
call   1030 <ldiv@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0xf4240,-0x38(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11c8 <inter_maxtoabs+0x98>
lea    -0x20(%rbp),%rdi
call   1040 <timerclear@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1050 <inter_maxto@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inter_maxtoabs>:
test   %rdi,%rdi
je     11b2 <inter_maxtoabs+0x82>
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
sub    %rdx,%rbx
sub    %ecx,%r12d
lea    0x1e8480(%r12),%edi
mov    $0xf4240,%esi
call   1030 <ldiv@plt>
cltq
add    %rax,%rbx
imul   $0xfff0bdc0,%eax,%eax
add    $0xfffffffffffffffe,%rbx
mov    %rbx,0x8(%rsp)
lea    0x1e8480(%r12,%rax,1),%ecx
mov    %ecx,0x10(%rsp)
jns    1199 <inter_maxtoabs+0x69>
lea    0x8(%rsp),%rdi
call   1040 <timerclear@plt>
mov    0x8(%rsp),%rbx
mov    0x10(%rsp),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <inter_maxto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.TYPE_3__ = type { i32 }
define void @inter_maxtoabs(%struct.timeval** %0, %struct.timeval* %1, i64 %2, i32 %3, i64 %4, i32 %5) {
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval**
%10 = alloca %struct.timeval*
%11 = alloca %struct.TYPE_3__
%12 = alloca %struct.TYPE_3__
%13 = bitcast %struct.timeval* %7 to { i64, i32 }*
%14 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %13, i32 0, i32 0
store i64 %2, i64* %14
%15 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %13, i32 0, i32 1
store i32 %3, i32* %15
%16 = bitcast %struct.timeval* %8 to { i64, i32 }*
%17 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %16, i32 0, i32 0
store i64 %4, i64* %17
%18 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %16, i32 0, i32 1
store i32 %5, i32* %18
store %struct.timeval** %0, %struct.timeval*** %9
store %struct.timeval* %1, %struct.timeval** %10
%19 = load %struct.timeval**, %struct.timeval*** %9
%20 = icmp ne %struct.timeval** %19, null
br i1 %20, label %22, label %21
21: ; preds = %6
br label %67
22: ; preds = %6
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%24 = load i64, i64* %23
%25 = add nsw i64 %24, 2
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%27 = load i64, i64* %26
%28 = sub nsw i64 %27, %25
store i64 %28, i64* %26
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%30 = load i32, i32* %29
%31 = sub nsw i32 %30, 2000000
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%33 = load i32, i32* %32
%34 = sub nsw i32 %33, %31
store i32 %34, i32* %32
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%36 = load i32, i32* %35
%37 = call i32 @ldiv(i32 %36, i32 1000000)
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.TYPE_3__* %11 to i8*
%40 = bitcast %struct.TYPE_3__* %12 to i8*
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%45 = load i64, i64* %44
%46 = add nsw i64 %45, %43
store i64 %46, i64* %44
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, 1000000
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%51 = load i32, i32* %50
%52 = sub nsw i32 %51, %49
store i32 %52, i32* %50
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%54 = load i64, i64* %53
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %22
%57 = call i32 @timerclear(%struct.timeval* %8)
br label %58
58: ; preds = %56, %22
%59 = load %struct.timeval**, %struct.timeval*** %9
%60 = load %struct.timeval*, %struct.timeval** %10
%61 = bitcast %struct.timeval* %8 to { i64, i32 }*
%62 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %61, i32 0, i32 1
%65 = load i32, i32* %64
%66 = call i32 @inter_maxto(%struct.timeval** %59, %struct.timeval* %60, i64 %63, i32 %65)
br label %67
67: ; preds = %58, %21
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define void @inter_maxtoabs(%struct.timeval** %0, %struct.timeval* %1, i64 %2, i32 %3, i64 %4, i32 %5) {
%7 = alloca %struct.timeval
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%10 = icmp eq %struct.timeval** %0, null
br i1 %10, label %30, label %11
11: ; preds = %6
%12 = sub i64 -2, %2
%13 = add i64 %12, %4
%14 = sub i32 2000000, %3
%15 = add i32 %14, %5
%16 = tail call i32 @ldiv(i32 %15, i32 1000000)
%17 = sext i32 %16 to i64
%18 = add nsw i64 %13, %17
store i64 %18, i64* %8
%19 = mul i32 %16, -1000000
%20 = add i32 %15, %19
store i32 %20, i32* %9
%21 = icmp slt i64 %18, 0
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = call i32 @timerclear(%struct.timeval* %7)
%24 = load i64, i64* %8
%25 = load i32, i32* %9
br label %26
26: ; preds = %22, %11
%27 = phi i32 [ %25, %22 ], [ %20, %11 ]
%28 = phi i64 [ %24, %22 ], [ %18, %11 ]
%29 = call i32 @inter_maxto(%struct.timeval** %0, %struct.timeval* %1, i64 %28, i32 %27)
br label %30
30: ; preds = %6, %26
ret void
}