#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 */

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
void snprintf_timeval(char *buf, size_t n, unsigned int sec,
                      unsigned int usec) {
  if (sec == 0)
    if (usec == 0)
      snprintf(buf, n, "    0");
    else if (usec < 1000)
      snprintf(buf, n, "%3dus", usec);
    else
      snprintf(buf, n, "%3dms", usec / 1000);
  else
    snprintf(buf, n, "%2d:%02d", sec / 60, sec % 60);
}


x86 assembly (clang, -O0):
<snprintf_timeval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ae <snprintf_timeval+0x9e>
cmpl   $0x0,-0x18(%rbp)
jne    1155 <snprintf_timeval+0x45>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xeb7(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11a9 <snprintf_timeval+0x99>
cmpl   $0x3e8,-0x18(%rbp)
jae    1180 <snprintf_timeval+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%ecx
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11a4 <snprintf_timeval+0x94>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
lea    0xe6f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11a9 <snprintf_timeval+0x99>
jmp    11e3 <snprintf_timeval+0xd3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
mov    $0x3c,%r8d
xor    %edx,%edx
div    %r8d
mov    %edx,%r8d
lea    0xe36(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf_timeval>:
test   %edx,%edx
je     113a <snprintf_timeval+0x2a>
mov    %edx,%r8d
mov    %edx,%eax
mov    $0x88888889,%ecx
imul   %rax,%rcx
shr    $0x25,%rcx
imul   $0x3c,%ecx,%eax
sub    %eax,%r8d
lea    0xedf(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>
test   %ecx,%ecx
je     1154 <snprintf_timeval+0x44>
cmp    $0x3e7,%ecx
ja     1162 <snprintf_timeval+0x52>
lea    0xeb9(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>
lea    0xea5(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>
mov    %ecx,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
lea    0xe96(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" 0\00"
@.str.1 = [6 x i8] c"%3dus\00"
@.str.2 = [6 x i8] c"%3dms\00"
@.str.3 = [9 x i8] c"%2d:%02d\00"
define void @snprintf_timeval(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %4
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i64, i64* %6
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %15, i64 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %33
18: ; preds = %11
%19 = load i32, i32* %8
%20 = icmp ult i32 %19, 1000
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = load i32, i32* %8
%25 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %32
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = load i32, i32* %8
%30 = udiv i32 %29, 1000
%31 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %27, i64 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %26, %21
br label %33
33: ; preds = %32, %14
br label %42
34: ; preds = %4
%35 = load i8*, i8** %5
%36 = load i64, i64* %6
%37 = load i32, i32* %7
%38 = udiv i32 %37, 60
%39 = load i32, i32* %7
%40 = urem i32 %39, 60
%41 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %35, i64 %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %40)
br label %42
42: ; preds = %34, %33
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" 0\00"
@.str.1 = [6 x i8] c"%3dus\00"
@.str.2 = [6 x i8] c"%3dms\00"
@.str.3 = [9 x i8] c"%2d:%02d\00"
define void @snprintf_timeval(i8* nocapture writeonly %0, i64 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %6, label %17
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %21
10: ; preds = %6
%11 = icmp ult i32 %3, 1000
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %3)
br label %21
14: ; preds = %10
%15 = udiv i32 %3, 1000
%16 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %21
17: ; preds = %4
%18 = udiv i32 %2, 60
%19 = urem i32 %2, 60
%20 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %8, %14, %12, %17
ret void
}