#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*/ printf(char *, long, ...);
void print_us_nicely(long us) {
  long a = 0;
  long b = 0;
  if (us > 1000) {
    a = us / 1000;
    b = us;
    while (b > 1000) {
      b -= 1000;
    }
    printf("%ld.%03d ms", a, b);
  } else if (us > 1000000) {
    a = us / 1000000;
    b = us;
    while (b > 1000000) {
      b -= 1000000;
    }
    printf("%ld.%03d s", a, b);
  } else {
    printf("%ld us", us);
  }
}


x86 assembly (clang, -O0):
<print_us_nicely>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x3e8,-0x8(%rbp)
jle    1190 <print_us_nicely+0x80>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x3e8,-0x18(%rbp)
jle    1175 <print_us_nicely+0x65>
mov    -0x18(%rbp),%rax
sub    $0x3e8,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <print_us_nicely+0x44>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120b <print_us_nicely+0xfb>
cmpq   $0xf4240,-0x8(%rbp)
jle    11f4 <print_us_nicely+0xe4>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xf4240,-0x18(%rbp)
jle    11d9 <print_us_nicely+0xc9>
mov    -0x18(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <print_us_nicely+0xa8>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1206 <print_us_nicely+0xf6>
mov    -0x8(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120b <print_us_nicely+0xfb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_us_nicely>:
mov    %rdi,%rsi
cmp    $0x3e9,%rdi
jl     1172 <print_us_nicely+0x62>
lea    -0x1(%rsi),%rdi
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%r8
9b c4 20
mul    %r8
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rax
neg    %rax
lea    (%rsi,%rax,1),%rcx
add    $0xffffffffffffffff,%rcx
sub    %rdi,%rcx
add    %rsi,%rcx
shr    $0x3,%rsi
mov    %rsi,%rax
mul    %r8
shr    $0x4,%rdx
lea    0xe9b(%rip),%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%ld.%03d ms\00"
@.str.1 = [11 x i8] c"%ld.%03d s\00"
@.str.2 = [7 x i8] c"%ld us\00"
define void @print_us_nicely(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
%5 = load i64, i64* %2
%6 = icmp sgt i64 %5, 1000
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = load i64, i64* %2
%9 = sdiv i64 %8, 1000
store i64 %9, i64* %3
%10 = load i64, i64* %2
store i64 %10, i64* %4
br label %11
11: ; preds = %14, %7
%12 = load i64, i64* %4
%13 = icmp sgt i64 %12, 1000
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %4
%16 = sub nsw i64 %15, 1000
store i64 %16, i64* %4
br label %11
17: ; preds = %11
%18 = load i64, i64* %3
%19 = load i64, i64* %4
%20 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %19)
br label %42
21: ; preds = %1
%22 = load i64, i64* %2
%23 = icmp sgt i64 %22, 1000000
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i64, i64* %2
%26 = sdiv i64 %25, 1000000
store i64 %26, i64* %3
%27 = load i64, i64* %2
store i64 %27, i64* %4
br label %28
28: ; preds = %31, %24
%29 = load i64, i64* %4
%30 = icmp sgt i64 %29, 1000000
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i64, i64* %4
%33 = sub nsw i64 %32, 1000000
store i64 %33, i64* %4
br label %28
34: ; preds = %28
%35 = load i64, i64* %3
%36 = load i64, i64* %4
%37 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %35, i64 %36)
br label %41
38: ; preds = %21
%39 = load i64, i64* %2
%40 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %38, %34
br label %42
42: ; preds = %41, %17
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%ld.%03d ms\00"
@.str.2 = [7 x i8] c"%ld us\00"
define void @print_us_nicely(i64 %0) {
%2 = icmp sgt i64 %0, 1000
br i1 %2, label %3, label %10
3: ; preds = %1
%4 = add nsw i64 %0, -1
%5 = urem i64 %4, 1000
%6 = sub nsw i64 %5, %4
%7 = udiv i64 %0, 1000
%8 = add nsw i64 %6, %0
%9 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %8)
br label %12
10: ; preds = %1
%11 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %0)
br label %12
12: ; preds = %10, %3
ret void
}