#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 */
typedef scalar_t__ time_t;
struct TYPE_4__ {
  int tv_sec;
  int tv_usec;
};
struct TYPE_3__ {
  int tv_sec;
  int tv_usec;
};
struct rusage {
  int ru_maxrss;
  int /*<<< orphan*/ ru_oublock;
  int /*<<< orphan*/ ru_inblock;
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int sprintf(char *, char *, int, int, ...);
scalar_t__ time(int /*<<< orphan*/ *);
const char *duration(time_t start, const struct rusage *usage) {
  static char buf[100];
  int t = (int)(time(NULL) - start);
  int p = sprintf(buf, "%2d:%02d", t / 60, t % 60);
  if (usage)
    sprintf(buf + p, "   %2ld:%02ld.%03ld/%ld:%02ld.%03ld%5ld%8ld/%ld",
            usage->ru_utime.tv_sec / 60, usage->ru_utime.tv_sec % 60,
            usage->ru_utime.tv_usec / 1000, usage->ru_stime.tv_sec / 60,
            usage->ru_stime.tv_sec % 60, usage->ru_stime.tv_usec / 1000,
            usage->ru_maxrss / 1024, usage->ru_inblock, usage->ru_oublock);
  return buf;
}


x86 assembly (clang, -O0):
<duration>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
sub    -0x18(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x2c(%rbp),%edx
lea    0x2ed8(%rip),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1243 <duration+0x123>
movslq -0x28(%rbp),%rax
lea    0x2eb1(%rip),%rdi
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %eax,%r8d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %eax,%r9d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r14d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %eax,%ebx
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    $0x400,%esi
cltd
idiv   %esi
mov    -0x30(%rbp),%edx
mov    %eax,%r11d
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r10d
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
lea    0xde3(%rip),%rsi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2df6(%rip),%rax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<duration>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edi,%edi
call   1030 <time@plt>
sub    %rbx,%rax
movslq %eax,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x5,%edx
add    %eax,%edx
imul   $0x3c,%edx,%eax
sub    %eax,%ecx
lea    0x2ee2(%rip),%r14
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
test   %r15,%r15
je     1239 <duration+0x119>
cltq
add    %rax,%r14
movslq 0x14(%r15),%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x5,%edx
add    %eax,%edx
imul   $0x3c,%edx,%eax
sub    %eax,%ecx
movslq 0x18(%r15),%rax
imul   $0x10624dd3,%rax,%r8
mov    %r8,%rax
shr    $0x3f,%rax
shr    $0x20,%r8
sar    $0x6,%r8d
add    %eax,%r8d
movslq 0xc(%r15),%r10
imul   $0xffffffff88888889,%r10,%r9
shr    $0x20,%r9
add    %r10d,%r9d
mov    %r9d,%eax
shr    $0x1f,%eax
sar    $0x5,%r9d
add    %eax,%r9d
imul   $0x3c,%r9d,%eax
sub    %eax,%r10d
movslq 0x10(%r15),%rax
imul   $0x10624dd3,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
shr    $0x20,%rbx
sar    $0x6,%ebx
add    %eax,%ebx
mov    (%r15),%eax
mov    0x4(%r15),%r11d
lea    0x3ff(%rax),%r12d
test   %eax,%eax
cmovns %eax,%r12d
sar    $0xa,%r12d
mov    0x8(%r15),%r15d
sub    $0x8,%rsp
lea    0xde7(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
push   %r11
push   %r15
push   %r12
push   %rbx
push   %r10
call   1040 <sprintf@plt>
add    $0x30,%rsp
lea    0x2e00(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rusage = type { i32, i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@duration.buf = internal global [100 x i8] zeroinitializer
@.str = [9 x i8] c"%2d:%02d\00"
@.str.1 = [48 x i8] c" %2ld:%02ld.%03ld/%ld:%02ld.%03ld%5ld%8ld/%ld\00"
define i8* @duration(i64 %0, %struct.rusage* %1) {
%3 = alloca i64
%4 = alloca %struct.rusage*
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
store %struct.rusage* %1, %struct.rusage** %4
%7 = call i64 @time(i32* null)
%8 = load i64, i64* %3
%9 = sub nsw i64 %7, %8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = sdiv i32 %11, 60
%13 = load i32, i32* %5
%14 = srem i32 %13, 60
%15 = call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @duration.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
store i32 %15, i32* %6
%16 = load %struct.rusage*, %struct.rusage** %4
%17 = icmp ne %struct.rusage* %16, null
br i1 %17, label %18, label %63
18: ; preds = %2
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @duration.buf, i64 0, i64 0), i64 %20
%22 = load %struct.rusage*, %struct.rusage** %4
%23 = getelementptr inbounds %struct.rusage, %struct.rusage* %22, i32 0, i32 4
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 60
%27 = load %struct.rusage*, %struct.rusage** %4
%28 = getelementptr inbounds %struct.rusage, %struct.rusage* %27, i32 0, i32 4
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = srem i32 %30, 60
%32 = load %struct.rusage*, %struct.rusage** %4
%33 = getelementptr inbounds %struct.rusage, %struct.rusage* %32, i32 0, i32 4
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = sdiv i32 %35, 1000
%37 = load %struct.rusage*, %struct.rusage** %4
%38 = getelementptr inbounds %struct.rusage, %struct.rusage* %37, i32 0, i32 3
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sdiv i32 %40, 60
%42 = load %struct.rusage*, %struct.rusage** %4
%43 = getelementptr inbounds %struct.rusage, %struct.rusage* %42, i32 0, i32 3
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = srem i32 %45, 60
%47 = load %struct.rusage*, %struct.rusage** %4
%48 = getelementptr inbounds %struct.rusage, %struct.rusage* %47, i32 0, i32 3
%49 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %48, i32 0, i32 1
%50 = load i32, i32* %49
%51 = sdiv i32 %50, 1000
%52 = load %struct.rusage*, %struct.rusage** %4
%53 = getelementptr inbounds %struct.rusage, %struct.rusage* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = sdiv i32 %54, 1024
%56 = load %struct.rusage*, %struct.rusage** %4
%57 = getelementptr inbounds %struct.rusage, %struct.rusage* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = load %struct.rusage*, %struct.rusage** %4
%60 = getelementptr inbounds %struct.rusage, %struct.rusage* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %31, i32 %36, i32 %41, i32 %46, i32 %51, i32 %55, i32 %58, i32 %61)
br label %63
63: ; preds = %18, %2
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @duration.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.rusage = type { i32, i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@duration.buf = internal global [100 x i8] zeroinitializer
@.str = [9 x i8] c"%2d:%02d\00"
@.str.1 = [48 x i8] c" %2ld:%02ld.%03ld/%ld:%02ld.%03ld%5ld%8ld/%ld\00"
define i8* @duration(i64 %0, %struct.rusage* %1) {
%3 = tail call i64 @time(i32* null)
%4 = sub nsw i64 %3, %0
%5 = trunc i64 %4 to i32
%6 = sdiv i32 %5, 60
%7 = srem i32 %5, 60
%8 = tail call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @duration.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = icmp eq %struct.rusage* %1, null
br i1 %9, label %35, label %10
10: ; preds = %2
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds [100 x i8], [100 x i8]* @duration.buf, i64 0, i64 %11
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 4, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 60
%16 = srem i32 %14, 60
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 4, i32 1
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 1000
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 3, i32 0
%21 = load i32, i32* %20
%22 = sdiv i32 %21, 60
%23 = srem i32 %21, 60
%24 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 3, i32 1
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 1000
%27 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%28 = load i32, i32* %27
%29 = sdiv i32 %28, 1024
%30 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16, i32 %19, i32 %22, i32 %23, i32 %26, i32 %29, i32 %31, i32 %33)
br label %35
35: ; preds = %10, %2
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @duration.buf, i64 0, i64 0)
}