#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 printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long);
void print_graph_duration(unsigned long long duration) {
  unsigned long usecs = duration / 1000;
  unsigned long nsecs_rem = duration % 1000;
  char msecs_str[21];
  char nsecs_str[5];
  int len;
  int i;
  sprintf(msecs_str, "%lu", usecs);
  len = printf("%lu", usecs);
  if (len < 7) {
    snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
    len += printf(".%s", nsecs_str);
  }
  printf(" us ");
  for (i = len; i < 7; i++)
    printf(" ");
  printf("|  ");
}


x86 assembly (clang, -O0):
<print_graph_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x7,-0x3c(%rbp)
jge    11c7 <print_graph_duration+0x97>
lea    -0x35(%rbp),%rdi
mov    $0x8,%esi
sub    -0x3c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe5a(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x35(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x7,-0x40(%rbp)
jge    1201 <print_graph_duration+0xd1>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11db <print_graph_duration+0xab>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_graph_duration>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%rbx
shr    $0x4,%rbx
lea    0xe93(%rip),%rbp
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x7,%eax
jge    1201 <print_graph_duration+0xc1>
mov    %eax,%ebp
imul   $0x3e8,%rbx,%rax
sub    %rax,%r14
mov    $0x8,%esi
sub    %ebp,%esi
lea    0xe5b(%rip),%rdx
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xe4a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %eax,%ebx
add    %ebp,%ebx
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x6,%ebx
jg     120f <print_graph_duration+0xcf>
mov    $0x7,%ebp
sub    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11f0 <print_graph_duration+0xb0>
jmp    120f <print_graph_duration+0xcf>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%lu\00"
@.str.1 = [6 x i8] c"%03lu\00"
@.str.2 = [4 x i8] c".%s\00"
@.str.3 = [5 x i8] c" us \00"
@.str.5 = [4 x i8] c"| \00"
define void @print_graph_duration(i64 %0) {
%2 = alloca [21 x i8]
%3 = alloca [5 x i8]
%4 = udiv i64 %0, 1000
%5 = urem i64 %0, 1000
%6 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %4)
%10 = icmp slt i32 %9, 7
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %25
13: ; preds = %1
%14 = sub nsw i32 8, %9
%15 = call i32 @snprintf(i8* %7, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%17 = add nsw i32 %16, %9
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp slt i32 %17, 7
br i1 %19, label %20, label %25
20: ; preds = %13, %20
%21 = phi i32 [ %23, %20 ], [ %17, %13 ]
%22 = call i32 @putchar(i32 32)
%23 = add i32 %21, 1
%24 = icmp eq i32 %23, 7
br i1 %24, label %25, label %20
25: ; preds = %20, %11, %13
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret void
}