#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 *, unsigned long, ...);
void print_speed(unsigned long speed) {
  unsigned long tmp;
  if (speed > 1000000) {
    tmp = speed % 10000;
    if (tmp >= 5000)
      speed += 10000;
    printf("%u.%02u GHz", ((unsigned int)speed / 1000000),
           ((unsigned int)(speed % 1000000) / 10000));
  } else if (speed > 100000) {
    tmp = speed % 1000;
    if (tmp >= 500)
      speed += 1000;
    printf("%u MHz", ((unsigned int)speed / 1000));
  } else if (speed > 1000) {
    tmp = speed % 100;
    if (tmp >= 50)
      speed += 100;
    printf("%u.%01u MHz", ((unsigned int)speed / 1000),
           ((unsigned int)(speed % 1000) / 100));
  } else
    printf("%lu kHz", speed);
  return;
}


x86 assembly (clang, -O0):
<print_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0xf4240,-0x8(%rbp)
jbe    1197 <print_speed+0x87>
mov    -0x8(%rbp),%rax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x1388,-0x10(%rbp)
jb     1158 <print_speed+0x48>
mov    -0x8(%rbp),%rax
add    $0x2710,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%eax
mov    %eax,%esi
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <print_speed+0x179>
cmpq   $0x186a0,-0x8(%rbp)
jbe    11f7 <print_speed+0xe7>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x1f4,-0x10(%rbp)
jb     11d3 <print_speed+0xc3>
mov    -0x8(%rbp),%rax
add    $0x3e8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%eax
mov    %eax,%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1284 <print_speed+0x174>
cmpq   $0x3e8,-0x8(%rbp)
jbe    126d <print_speed+0x15d>
mov    -0x8(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x32,-0x10(%rbp)
jb     122e <print_speed+0x11e>
mov    -0x8(%rbp),%rax
add    $0x64,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%eax
mov    %eax,%esi
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%edx
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127f <print_speed+0x16f>
mov    -0x8(%rbp),%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1284 <print_speed+0x174>
jmp    1289 <print_speed+0x179>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_speed>:
mov    %rdi,%rsi
cmp    $0xf4241,%rdi
jb     1195 <print_speed+0x85>
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mov    %rsi,%rax
mul    %rcx
shr    $0xb,%rdx
imul   $0x2710,%rdx,%rax
mov    %rsi,%rdx
sub    %rax,%rdx
lea    0x2710(%rsi),%rcx
cmp    $0x1388,%rdx
cmovb  %rsi,%rcx
mov    %ecx,%eax
imul   $0x431bde83,%rax,%rsi
shr    $0x32,%rsi
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
mul    %rdx
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
sub    %rax,%rcx
mov    $0xd1b71759,%edx
imul   %rcx,%rdx
shr    $0x2d,%rdx
lea    0xe72(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x186a1,%rsi
jb     11e0 <print_speed+0xd0>
mov    %esi,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
mov    %esi,%ecx
sub    %eax,%ecx
lea    0x3e8(%rsi),%eax
cmp    $0x1f4,%ecx
cmovb  %rsi,%rax
mov    %eax,%eax
imul   $0x10624dd3,%rax,%rsi
shr    $0x26,%rsi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x3e9,%rsi
jb     123a <print_speed+0x12a>
mov    %esi,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
mov    %esi,%ecx
sub    %eax,%ecx
lea    0x64(%rsi),%rax
cmp    $0x32,%ecx
cmovb  %rsi,%rax
mov    %eax,%ecx
imul   $0x10624dd3,%rcx,%rsi
shr    $0x26,%rsi
imul   $0x3e8,%esi,%ecx
sub    %ecx,%eax
movzwl %ax,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%edx
shr    $0x11,%edx
lea    0xde0(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xdde(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%02u GHz\00"
@.str.1 = [7 x i8] c"%u MHz\00"
@.str.2 = [12 x i8] c"%u.%01u MHz\00"
@.str.3 = [8 x i8] c"%lu kHz\00"
define void @print_speed(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp ugt i64 %4, 1000000
br i1 %5, label %6, label %24
6: ; preds = %1
%7 = load i64, i64* %2
%8 = urem i64 %7, 10000
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = icmp uge i64 %9, 5000
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i64, i64* %2
%13 = add i64 %12, 10000
store i64 %13, i64* %2
br label %14
14: ; preds = %11, %6
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
%17 = udiv i32 %16, 1000000
%18 = zext i32 %17 to i64
%19 = load i64, i64* %2
%20 = urem i64 %19, 1000000
%21 = trunc i64 %20 to i32
%22 = udiv i32 %21, 10000
%23 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %18, i32 %22)
br label %67
24: ; preds = %1
%25 = load i64, i64* %2
%26 = icmp ugt i64 %25, 100000
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i64, i64* %2
%29 = urem i64 %28, 1000
store i64 %29, i64* %3
%30 = load i64, i64* %3
%31 = icmp uge i64 %30, 500
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i64, i64* %2
%34 = add i64 %33, 1000
store i64 %34, i64* %2
br label %35
35: ; preds = %32, %27
%36 = load i64, i64* %2
%37 = trunc i64 %36 to i32
%38 = udiv i32 %37, 1000
%39 = zext i32 %38 to i64
%40 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %39)
br label %66
41: ; preds = %24
%42 = load i64, i64* %2
%43 = icmp ugt i64 %42, 1000
br i1 %43, label %44, label %62
44: ; preds = %41
%45 = load i64, i64* %2
%46 = urem i64 %45, 100
store i64 %46, i64* %3
%47 = load i64, i64* %3
%48 = icmp uge i64 %47, 50
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i64, i64* %2
%51 = add i64 %50, 100
store i64 %51, i64* %2
br label %52
52: ; preds = %49, %44
%53 = load i64, i64* %2
%54 = trunc i64 %53 to i32
%55 = udiv i32 %54, 1000
%56 = zext i32 %55 to i64
%57 = load i64, i64* %2
%58 = urem i64 %57, 1000
%59 = trunc i64 %58 to i32
%60 = udiv i32 %59, 100
%61 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %56, i32 %60)
br label %65
62: ; preds = %41
%63 = load i64, i64* %2
%64 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %63)
br label %65
65: ; preds = %62, %52
br label %66
66: ; preds = %65, %35
br label %67
67: ; preds = %66, %14
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%02u GHz\00"
@.str.1 = [7 x i8] c"%u MHz\00"
@.str.2 = [12 x i8] c"%u.%01u MHz\00"
@.str.3 = [8 x i8] c"%lu kHz\00"
define void @print_speed(i64 %0) {
%2 = icmp ugt i64 %0, 1000000
br i1 %2, label %3, label %15
3: ; preds = %1
%4 = urem i64 %0, 10000
%5 = icmp ugt i64 %4, 4999
%6 = add i64 %0, 10000
%7 = select i1 %5, i64 %6, i64 %0
%8 = trunc i64 %7 to i32
%9 = udiv i32 %8, 1000000
%10 = zext i32 %9 to i64
%11 = urem i64 %7, 1000000
%12 = trunc i64 %11 to i32
%13 = udiv i32 %12, 10000
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %10, i32 %13)
br label %45
15: ; preds = %1
%16 = icmp ugt i64 %0, 100000
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = trunc i64 %0 to i32
%19 = urem i32 %18, 1000
%20 = icmp ugt i32 %19, 499
%21 = add nuw nsw i64 %0, 1000
%22 = select i1 %20, i64 %21, i64 %0
%23 = trunc i64 %22 to i32
%24 = udiv i32 %23, 1000
%25 = zext i32 %24 to i64
%26 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %25)
br label %45
27: ; preds = %15
%28 = icmp ugt i64 %0, 1000
br i1 %28, label %29, label %43
29: ; preds = %27
%30 = trunc i64 %0 to i32
%31 = urem i32 %30, 100
%32 = icmp ugt i32 %31, 49
%33 = add nuw nsw i64 %0, 100
%34 = select i1 %32, i64 %33, i64 %0
%35 = trunc i64 %34 to i32
%36 = udiv i32 %35, 1000
%37 = zext i32 %36 to i64
%38 = urem i32 %35, 1000
%39 = trunc i32 %38 to i16
%40 = udiv i16 %39, 100
%41 = zext i16 %40 to i32
%42 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 %37, i32 %41)
br label %45
43: ; preds = %27
%44 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %0)
br label %45
45: ; preds = %17, %43, %29, %3
ret void
}