#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 */
scalar_t__ roadmap_math_get_orientation();
int normalize_angle(int angle) {
  angle += roadmap_math_get_orientation();
  while (angle > 360)
    angle -= 360;
  while (angle < 0)
    angle += 360;
  if (angle >= 180)
    angle -= 180;
  angle -= 90;
  return angle;
}


x86 assembly (clang, -O0):
<normalize_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <roadmap_math_get_orientation@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
cmpl   $0x168,-0x4(%rbp)
jle    114c <normalize_angle+0x3c>
mov    -0x4(%rbp),%eax
sub    $0x168,%eax
mov    %eax,-0x4(%rbp)
jmp    112f <normalize_angle+0x1f>
jmp    1151 <normalize_angle+0x41>
cmpl   $0x0,-0x4(%rbp)
jge    116b <normalize_angle+0x5b>
mov    -0x4(%rbp),%eax
add    $0x168,%eax
mov    %eax,-0x4(%rbp)
jmp    1151 <normalize_angle+0x41>
cmpl   $0xb4,-0x4(%rbp)
jl     1183 <normalize_angle+0x73>
mov    -0x4(%rbp),%eax
sub    $0xb4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x5a,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_angle>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <roadmap_math_get_orientation@plt>
lea    (%rax,%r14,1),%ecx
cmp    $0x168,%ecx
mov    $0x168,%edx
cmovl  %ecx,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x167,%esi
shr    $0x3,%esi
imul   $0x16c16c17,%rsi,%rdx
shr    $0x22,%rdx
imul   $0x168,%edx,%edx
sub    %edx,%ecx
test   %ecx,%ecx
cmovg  %ecx,%ebx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %esi,%ecx
sub    %ecx,%ebx
shr    $0x3,%ebx
imul   $0x16c16c17,%rbx,%rcx
shr    $0x22,%rcx
add    %esi,%ecx
imul   $0x168,%ecx,%ecx
add    %r14d,%ecx
add    %ecx,%eax
sub    %edx,%eax
lea    -0xb4(%rax),%ecx
cmp    $0xb4,%eax
cmovae %ecx,%eax
add    $0xffffffa6,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @normalize_angle(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i64 (...) @roadmap_math_get_orientation()
%4 = load i32, i32* %2
%5 = sext i32 %4 to i64
%6 = add nsw i64 %5, %3
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 360
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 360
store i32 %13, i32* %2
br label %8
14: ; preds = %8
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 360
store i32 %20, i32* %2
br label %15
21: ; preds = %15
%22 = load i32, i32* %2
%23 = icmp sge i32 %22, 180
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sub nsw i32 %25, 180
store i32 %26, i32* %2
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 90
store i32 %29, i32* %2
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @normalize_angle(i32 %0) {
%2 = tail call i64 (...) @roadmap_math_get_orientation()
%3 = trunc i64 %2 to i32
%4 = add i32 %3, %0
%5 = add i32 %4, 359
%6 = call i32 @llvm.smin.i32(i32 %4, i32 360)
%7 = sub i32 %5, %6
%8 = urem i32 %7, 360
%9 = sub i32 %7, %8
%10 = sub i32 %4, %9
%11 = call i32 @llvm.smax.i32(i32 %10, i32 0)
%12 = lshr i32 %10, 31
%13 = add i32 %12, %10
%14 = sub i32 %11, %13
%15 = udiv i32 %14, 360
%16 = add nuw nsw i32 %12, %15
%17 = mul i32 %16, 360
%18 = add i32 %17, %0
%19 = add i32 %18, %3
%20 = sub i32 %19, %9
%21 = icmp ugt i32 %20, 179
%22 = add nsw i32 %20, -180
%23 = select i1 %21, i32 %22, i32 %20
%24 = add nsw i32 %23, -90
ret i32 %24
}