#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 */
typedef int int64_t;

/* Variables and functions */
char find_unit(int64_t *data) {
  char unit = 'n';
  while ((*data) >= 1000) {
    (*data) = (*data) / 1000;
    if (unit == 'n') {
      unit = 'u';
    } else if (unit == 'u') {
      unit = 'm';
    } else if (unit == 'm') {
      unit = '\0';
    } else if (unit == '\0') {
      unit = 'k';
    }
  }
  return unit;
}


x86 assembly (clang, -O0):
<find_unit>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movb   $0x6e,-0x9(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x3e8,(%rax)
jl     1199 <find_unit+0x99>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
movsbl -0x9(%rbp),%eax
cmp    $0x6e,%eax
jne    1148 <find_unit+0x48>
movb   $0x75,-0x9(%rbp)
jmp    1194 <find_unit+0x94>
movsbl -0x9(%rbp),%eax
cmp    $0x75,%eax
jne    115e <find_unit+0x5e>
movb   $0x6d,-0x9(%rbp)
jmp    118f <find_unit+0x8f>
movsbl -0x9(%rbp),%eax
cmp    $0x6d,%eax
jne    1174 <find_unit+0x74>
movb   $0x0,-0x9(%rbp)
jmp    118a <find_unit+0x8a>
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    1185 <find_unit+0x85>
movb   $0x6b,-0x9(%rbp)
jmp    118a <find_unit+0x8a>
jmp    118f <find_unit+0x8f>
jmp    1194 <find_unit+0x94>
jmp    110c <find_unit+0xc>
movsbl -0x9(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_unit>:
mov    (%rdi),%ecx
mov    $0x6e,%al
cmp    $0x3e8,%ecx
jl     116c <find_unit+0x6c>
mov    $0x6e,%al
mov    $0x6b,%edx
jmp    112a <find_unit+0x2a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x75,%al
cmp    $0xf423f,%esi
jbe    116a <find_unit+0x6a>
mov    %ecx,%esi
mov    %ecx,%ecx
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
cmp    $0x6d,%al
je     1150 <find_unit+0x50>
cmp    $0x6e,%al
je     1120 <find_unit+0x20>
cmp    $0x75,%al
jne    1160 <find_unit+0x60>
mov    $0x6d,%al
jmp    1122 <find_unit+0x22>
nopl   0x0(%rax)
xor    %eax,%eax
jmp    1122 <find_unit+0x22>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %al,%al
movzbl %al,%eax
cmove  %edx,%eax
jmp    1122 <find_unit+0x22>
mov    %ecx,(%rdi)
ret

LLVM IR (-O0):
define signext i8 @find_unit(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
store i8 110, i8* %3
br label %4
4: ; preds = %35, %1
%5 = load i32*, i32** %2
%6 = load i32, i32* %5
%7 = icmp sge i32 %6, 1000
br i1 %7, label %8, label %36
8: ; preds = %4
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000
%12 = load i32*, i32** %2
store i32 %11, i32* %12
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 110
br i1 %15, label %16, label %17
16: ; preds = %8
store i8 117, i8* %3
br label %35
17: ; preds = %8
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 117
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 109, i8* %3
br label %34
22: ; preds = %17
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 109
br i1 %25, label %26, label %27
26: ; preds = %22
store i8 0, i8* %3
br label %33
27: ; preds = %22
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i8 107, i8* %3
br label %32
32: ; preds = %31, %27
br label %33
33: ; preds = %32, %26
br label %34
34: ; preds = %33, %21
br label %35
35: ; preds = %34, %16
br label %4
36: ; preds = %4
%37 = load i8, i8* %3
ret i8 %37
}

LLVM IR (-O2):
define signext i8 @find_unit(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp sgt i32 %2, 999
br i1 %3, label %4, label %17
4: ; preds = %1, %13
%5 = phi i8 [ %14, %13 ], [ 110, %1 ]
%6 = phi i32 [ %7, %13 ], [ %2, %1 ]
%7 = udiv i32 %6, 1000
switch i8 %5, label %10 [
i8 110, label %13
i8 117, label %8
i8 109, label %9
]
8: ; preds = %4
br label %13
9: ; preds = %4
br label %13
10: ; preds = %4
%11 = icmp eq i8 %5, 0
%12 = select i1 %11, i8 107, i8 %5
br label %13
13: ; preds = %4, %8, %10, %9
%14 = phi i8 [ 109, %8 ], [ 0, %9 ], [ %12, %10 ], [ 117, %4 ]
%15 = icmp ugt i32 %6, 999999
br i1 %15, label %4, label %16
16: ; preds = %13
store i32 %7, i32* %0
br label %17
17: ; preds = %16, %1
%18 = phi i8 [ %14, %16 ], [ 110, %1 ]
ret i8 %18
}