long air_soar_round_off_angle(long n, long m) {
  long unbounded_rounded, bounded_rounded;
  if (n < 0)
    unbounded_rounded = m * (long)((n - (long)(m / 2)) / m);
  else
    unbounded_rounded = m * (long)((n + (long)(m / 2)) / m);
  bounded_rounded = (unbounded_rounded % 360);
  if (bounded_rounded > 180)
    bounded_rounded -= 360;
  if (bounded_rounded <= -180)
    bounded_rounded += 360;
  return bounded_rounded;
}


x86 assembly (clang, -O0):
<air_soar_round_off_angle>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1159 <air_soar_round_off_angle+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1196 <air_soar_round_off_angle+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x168,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
cmpq   $0xb4,-0x20(%rbp)
jle    11c4 <air_soar_round_off_angle+0xc4>
mov    -0x20(%rbp),%rax
sub    $0x168,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffff4c,-0x20(%rbp)
ff
jg     11e0 <air_soar_round_off_angle+0xe0>
mov    -0x20(%rbp),%rax
add    $0x168,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<air_soar_round_off_angle>:
mov    %rdi,%rax
not    %rax
shr    $0x3f,%rax
lea    -0x2(,%rax,4),%rcx
ff
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     112b <air_soar_round_off_angle+0x2b>
mov    %rsi,%rax
cqto
idiv   %rcx
mov    %rax,%rcx
jmp    1133 <air_soar_round_off_angle+0x33>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
add    %rdi,%rcx
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     114c <air_soar_round_off_angle+0x4c>
mov    %rcx,%rax
cqto
idiv   %rsi
jmp    1152 <air_soar_round_off_angle+0x52>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
sub    %rdx,%rcx
movabs $0x2d82d82d82d82d83,%rdx
d8 82 2d
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x6,%rdx
add    %rax,%rdx
imul   $0x168,%rdx,%rax
mov    %rcx,%rdx
sub    %rax,%rdx
neg    %rax
cmp    $0xb5,%rdx
lea    -0x168(%rcx,%rax,1),%rcx
ff
cmovl  %rdx,%rcx
lea    0x168(%rcx),%rax
cmp    $0xffffffffffffff4d,%rcx
cmovge %rcx,%rax
ret

LLVM IR (-O0):
define i64 @air_soar_round_off_angle(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i64, i64* %4
%11 = load i64, i64* %3
%12 = load i64, i64* %4
%13 = sdiv i64 %12, 2
%14 = sub nsw i64 %11, %13
%15 = load i64, i64* %4
%16 = sdiv i64 %14, %15
%17 = mul nsw i64 %10, %16
store i64 %17, i64* %5
br label %27
18: ; preds = %2
%19 = load i64, i64* %4
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = sdiv i64 %21, 2
%23 = add nsw i64 %20, %22
%24 = load i64, i64* %4
%25 = sdiv i64 %23, %24
%26 = mul nsw i64 %19, %25
store i64 %26, i64* %5
br label %27
27: ; preds = %18, %9
%28 = load i64, i64* %5
%29 = srem i64 %28, 360
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = icmp sgt i64 %30, 180
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i64, i64* %6
%34 = sub nsw i64 %33, 360
store i64 %34, i64* %6
br label %35
35: ; preds = %32, %27
%36 = load i64, i64* %6
%37 = icmp sle i64 %36, -180
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i64, i64* %6
%40 = add nsw i64 %39, 360
store i64 %40, i64* %6
br label %41
41: ; preds = %38, %35
%42 = load i64, i64* %6
ret i64 %42
}

LLVM IR (-O2):
define i64 @air_soar_round_off_angle(i64 %0, i64 %1) {
%3 = icmp slt i64 %0, 0
%4 = select i1 %3, i64 -2, i64 2
%5 = sdiv i64 %1, %4
%6 = add i64 %5, %0
%7 = srem i64 %6, %1
%8 = sub i64 %6, %7
%9 = srem i64 %8, 360
%10 = icmp sgt i64 %9, 180
%11 = add nsw i64 %9, -360
%12 = select i1 %10, i64 %11, i64 %9
%13 = icmp slt i64 %12, -179
%14 = add nsw i64 %12, 360
%15 = select i1 %13, i64 %14, i64 %12
ret i64 %15
}