#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 abs(int);
int returnMid(int top, int bot) {
  int mid;
  mid = abs(((bot + top) / 2));
  while ((mid % 16) != 0)
    mid++;
  if (mid >= top) {
    mid = abs(((bot + top) / 2));
    while ((mid % 16) != 0)
      mid--;
  }
  return mid;
}


x86 assembly (clang, -O0):
<returnMid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <abs@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1158 <returnMid+0x48>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <returnMid+0x26>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     11a3 <returnMid+0x93>
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <abs@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     119e <returnMid+0x8e>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <returnMid+0x6c>
jmp    11a3 <returnMid+0x93>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<returnMid>:
lea    (%rsi,%rdi,1),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
mov    %eax,%ecx
neg    %ecx
and    $0xf,%ecx
add    %eax,%ecx
and    $0x7ffffff0,%eax
cmp    %edi,%ecx
cmovl  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @returnMid(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* %3
%8 = add nsw i32 %6, %7
%9 = sdiv i32 %8, 2
%10 = call i32 @abs(i32 %9)
store i32 %10, i32* %5
br label %11
11: ; preds = %15, %2
%12 = load i32, i32* %5
%13 = srem i32 %12, 16
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %11
18: ; preds = %11
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp sge i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = add nsw i32 %23, %24
%26 = sdiv i32 %25, 2
%27 = call i32 @abs(i32 %26)
store i32 %27, i32* %5
br label %28
28: ; preds = %32, %22
%29 = load i32, i32* %5
%30 = srem i32 %29, 16
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
br label %28
35: ; preds = %28
br label %36
36: ; preds = %35, %18
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
define i32 @returnMid(i32 %0, i32 %1) {
%3 = add nsw i32 %1, %0
%4 = sdiv i32 %3, 2
%5 = tail call i32 @llvm.abs.i32(i32 %4, i1 true)
%6 = sub nsw i32 0, %5
%7 = and i32 %6, 15
%8 = add nuw nsw i32 %5, %7
%9 = icmp slt i32 %8, %0
%10 = and i32 %5, 2147483632
%11 = select i1 %9, i32 %8, i32 %10
ret i32 %11
}