#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 uint16_t;

/* Variables and functions */
int convertAgcToNative(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
uint16_t addAgc(uint16_t n1, uint16_t n2) {
  int i1, i2, sum;
  i1 = convertAgcToNative(n1);
  i2 = convertAgcToNative(n2);
  sum = i1 + i2;
  if (sum > 16383) {
    sum -= 16384;
    sum++;
  } else if (sum < -16383) {
    sum += 16384;
    sum--;
  }
  if (sum > 16383 || sum < -16383)
    fprintf(stderr, "Error: arithmetic overflow.\n");
  if (sum >= 0)
    return (sum);
  return (077777 & ~(-sum));
}


x86 assembly (clang, -O0):
<addAgc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <convertAgcToNative@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <convertAgcToNative@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3fff,-0x18(%rbp)
jle    1173 <addAgc+0x53>
mov    -0x18(%rbp),%eax
sub    $0x4000,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <addAgc+0x79>
cmpl   $0xffffc001,-0x18(%rbp)
jge    1194 <addAgc+0x74>
mov    -0x18(%rbp),%eax
add    $0x4000,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <addAgc+0x79>
cmpl   $0x3fff,-0x18(%rbp)
jg     11b3 <addAgc+0x93>
cmpl   $0xffffc001,-0x18(%rbp)
jge    11c8 <addAgc+0xa8>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1030 <fprintf@plt>
cmpl   $0x0,-0x18(%rbp)
jl     11dd <addAgc+0xbd>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <addAgc+0xcd>
xor    %eax,%eax
sub    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
and    $0x7fff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addAgc>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1040 <convertAgcToNative@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <convertAgcToNative@plt>
lea    (%rax,%rbx,1),%ecx
cmp    $0xffffc001,%ecx
lea    0x3fff(%rax,%rbx,1),%edx
cmovge %ecx,%edx
cmp    $0x4000,%ecx
lea    -0x3fff(%rax,%rbx,1),%ebx
cmovl  %edx,%ebx
lea    -0x4000(%rbx),%eax
cmp    $0xffff8000,%eax
ja     1178 <addAgc+0x58>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x1(%rbx),%eax
and    $0x7fff,%eax
test   %ebx,%ebx
cmovns %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Error: arithmetic overflow.\0A\00"
define i32 @addAgc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = call i32 @convertAgcToNative(i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %5
%12 = call i32 @convertAgcToNative(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = add nsw i32 %13, %14
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp sgt i32 %16, 16383
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* %8
%20 = sub nsw i32 %19, 16384
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %32
23: ; preds = %2
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, -16383
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 16384
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = add nsw i32 %29, -1
store i32 %30, i32* %8
br label %31
31: ; preds = %26, %23
br label %32
32: ; preds = %31, %18
%33 = load i32, i32* %8
%34 = icmp sgt i32 %33, 16383
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, -16383
br i1 %37, label %38, label %41
38: ; preds = %35, %32
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %38, %35
%42 = load i32, i32* %8
%43 = icmp sge i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = load i32, i32* %8
store i32 %45, i32* %3
br label %51
46: ; preds = %41
%47 = load i32, i32* %8
%48 = sub nsw i32 0, %47
%49 = xor i32 %48, -1
%50 = and i32 32767, %49
store i32 %50, i32* %3
br label %51
51: ; preds = %46, %44
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Error: arithmetic overflow.\0A\00"
define i32 @addAgc(i32 %0, i32 %1) {
%3 = tail call i32 @convertAgcToNative(i32 %0)
%4 = tail call i32 @convertAgcToNative(i32 %1)
%5 = add nsw i32 %4, %3
%6 = icmp sgt i32 %5, 16383
%7 = add nsw i32 %5, -16383
%8 = icmp slt i32 %5, -16383
%9 = add nsw i32 %5, 16383
%10 = select i1 %8, i32 %9, i32 %5
%11 = select i1 %6, i32 %7, i32 %10
%12 = add i32 %11, -16384
%13 = icmp ult i32 %12, -32767
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %2, %14
%18 = icmp sgt i32 %11, -1
%19 = add i32 %11, 32767
%20 = and i32 %19, 32767
%21 = select i1 %18, i32 %11, i32 %20
ret i32 %21
}