#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_4__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_3__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
void get_cputime_from_rusage(struct rusage *r, struct timeval *dest_tv) {
  dest_tv->tv_sec = r->ru_utime.tv_sec + r->ru_stime.tv_sec;
  dest_tv->tv_usec = r->ru_utime.tv_usec + r->ru_stime.tv_usec;
  if (dest_tv->tv_usec >= (1000000)) {
    dest_tv->tv_usec -= (1000000);
    dest_tv->tv_sec++;
  }
}


x86 assembly (clang, -O0):
<get_cputime_from_rusage>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xf4240,(%rax)
jl     1165 <get_cputime_from_rusage+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cputime_from_rusage>:
mov    0x8(%rdi),%rax
add    0x18(%rdi),%rax
mov    %rax,0x8(%rsi)
mov    (%rdi),%ecx
add    0x10(%rdi),%ecx
mov    %ecx,(%rsi)
cmp    $0xf4240,%ecx
jl     112b <get_cputime_from_rusage+0x2b>
add    $0xfff0bdc0,%ecx
mov    %ecx,(%rsi)
add    $0x1,%rax
mov    %rax,0x8(%rsi)
ret

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

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i64 }
%struct.TYPE_3__ = type { i32, i64 }
%struct.timeval = type { i32, i64 }
define void @get_cputime_from_rusage(%struct.rusage* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 0, i32 1
%6 = load i64, i64* %5
%7 = add nsw i64 %6, %4
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 %7, i64* %8
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, %10
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 %13, i32* %14
%15 = icmp sgt i32 %13, 999999
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = add nsw i32 %13, -1000000
store i32 %17, i32* %14
%18 = add nsw i64 %7, 1
store i64 %18, i64* %8
br label %19
19: ; preds = %16, %2
ret void
}