#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 long long int64_t;

/* Variables and functions */
const char *hazer_format_nanodegrees2compass(int64_t nanodegrees,
                                             const char *compass[],
                                             size_t count) {
  size_t division = 0;
  size_t index = 0;
  while (nanodegrees < 0) {
    nanodegrees += 360000000000LL;
  }
  nanodegrees %= 360000000000LL;
  index = nanodegrees / 1000000LL;
  division = 360000 / count;
  index += division / 2;
  index %= 360000;
  index /= division;
  return compass[index];
}


x86 assembly (clang, -O0):
<hazer_format_nanodegrees2compass>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1142 <hazer_format_nanodegrees2compass+0x42>
movabs $0x53d1ac1000,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <hazer_format_nanodegrees2compass+0x20>
mov    -0x8(%rbp),%rax
movabs $0x53d1ac1000,%rcx
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    $0x57e40,%eax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x57e40,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hazer_format_nanodegrees2compass>:
xor    %r9d,%r9d
test   %rdi,%rdi
mov    $0x0,%eax
cmovg  %rdi,%rax
mov    %rdx,%r8
xor    %ecx,%ecx
sub    %rdi,%rax
setne  %cl
sub    %rcx,%rax
movabs $0x61bbff785469b455,%r10
ff bb 61
mul    %r10
shr    $0x25,%rdx
add    %rdx,%rcx
movabs $0x53d1ac1000,%r11
imul   %r11,%rcx
add    %rdi,%rcx
mov    %rcx,%rax
mul    %r10
shr    $0x25,%rdx
imul   %r11,%rdx
sub    %rdx,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
mul    %rdx
mov    %rdx,%rdi
shr    $0x12,%rdi
cmp    $0x57e40,%r8
ja     1180 <hazer_format_nanodegrees2compass+0x80>
mov    $0x57e40,%eax
xor    %edx,%edx
div    %r8d
mov    %eax,%r9d
mov    %r9,%rax
shr    %rax
add    %edi,%eax
mov    %eax,%ecx
shr    $0x6,%ecx
imul   $0x2e9a77,%rcx,%rcx
shr    $0x22,%rcx
imul   $0x57e40,%ecx,%ecx
sub    %ecx,%eax
xor    %edx,%edx
div    %r9d
mov    (%rsi,%rax,8),%rax
ret

LLVM IR (-O0):
define i8* @hazer_format_nanodegrees2compass(i64 %0, i8** %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %4
store i8** %1, i8*** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
br label %9
9: ; preds = %12, %3
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i64, i64* %4
%14 = add nsw i64 %13, 360000000000
store i64 %14, i64* %4
br label %9
15: ; preds = %9
%16 = load i64, i64* %4
%17 = srem i64 %16, 360000000000
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = sdiv i64 %18, 1000000
store i64 %19, i64* %8
%20 = load i64, i64* %6
%21 = udiv i64 360000, %20
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = udiv i64 %22, 2
%24 = load i64, i64* %8
%25 = add i64 %24, %23
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = urem i64 %26, 360000
store i64 %27, i64* %8
%28 = load i64, i64* %7
%29 = load i64, i64* %8
%30 = udiv i64 %29, %28
store i64 %30, i64* %8
%31 = load i8**, i8*** %5
%32 = load i64, i64* %8
%33 = getelementptr inbounds i8*, i8** %31, i64 %32
%34 = load i8*, i8** %33
ret i8* %34
}

LLVM IR (-O2):
define i8* @hazer_format_nanodegrees2compass(i64 %0, i8** nocapture %1, i64 %2) {
%4 = call i64 @llvm.smax.i64(i64 %0, i64 0)
%5 = sub i64 %4, %0
%6 = icmp ne i64 %5, 0
%7 = zext i1 %6 to i64
%8 = sub i64 %5, %7
%9 = udiv i64 %8, 360000000000
%10 = add nuw nsw i64 %9, %7
%11 = mul i64 %10, 360000000000
%12 = add i64 %11, %0
%13 = urem i64 %12, 360000000000
%14 = udiv i64 %13, 1000000
%15 = udiv i64 360000, %2
%16 = lshr i64 %15, 1
%17 = add nuw nsw i64 %16, %14
%18 = trunc i64 %17 to i32
%19 = urem i32 %18, 360000
%20 = trunc i64 %15 to i32
%21 = udiv i32 %19, %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
ret i8* %24
}