const char *scale(int *hop) {
  if (*hop > -1000 && *hop < 10000)
    return (" ms");
  *hop /= 1000;
  if (*hop > -1000 && *hop < 10000)
    return (" s ");
  return ("s ");
}


x86 assembly (clang, -O0):
<scale>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0xfffffc18,(%rax)
jle    1138 <scale+0x38>
mov    -0x10(%rbp),%rax
cmpl   $0x2710,(%rax)
jge    1138 <scale+0x38>
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118d <scale+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xfffffc18,(%rax)
jle    1182 <scale+0x82>
mov    -0x10(%rbp),%rax
cmpl   $0x2710,(%rax)
jge    1182 <scale+0x82>
lea    0xe8b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118d <scale+0x8d>
lea    0xe7c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale>:
mov    (%rdi),%eax
lea    0x3e7(%rax),%ecx
cmp    $0x2af7,%ecx
jae    1118 <scale+0x18>
lea    0xee9(%rip),%rax
ret
movslq %eax,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rdi)
add    $0xf423f,%eax
cmp    $0xa7d8bf,%eax
lea    0xec2(%rip),%rcx
lea    0xebc(%rip),%rax
cmovb  %rcx,%rax
ret

LLVM IR (-O0):
@.str = [4 x i8] c" ms\00"
@.str.1 = [4 x i8] c" s \00"
@.str.2 = [3 x i8] c"s \00"
define i8* @scale(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32*, i32** %3
%5 = load i32, i32* %4
%6 = icmp sgt i32 %5, -1000
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32*, i32** %3
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 10000
br i1 %10, label %11, label %12
11: ; preds = %7
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
br label %25
12: ; preds = %7, %1
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
store i32 %15, i32* %13
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = icmp sgt i32 %17, -1000
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = icmp slt i32 %21, 10000
br i1 %22, label %23, label %24
23: ; preds = %19
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %25
24: ; preds = %19, %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %25
25: ; preds = %24, %23, %11
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [4 x i8] c" ms\00"
@.str.1 = [4 x i8] c" s \00"
@.str.2 = [3 x i8] c"s \00"
define i8* @scale(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = add i32 %2, 999
%4 = icmp ult i32 %3, 10999
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = sdiv i32 %2, 1000
store i32 %6, i32* %0
%7 = add i32 %2, 999999
%8 = icmp ult i32 %7, 10999999
%9 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %10
10: ; preds = %5, %1
%11 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %1 ], [ %9, %5 ]
ret i8* %11
}