#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;
typedef int int16_t;

/* Variables and functions */
int addAgc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
uint16_t generateBuggerWord(int verbose, int bank, int length, int16_t *code) {
  uint16_t checksum = 0, bugger = 0;
  int i = 0;
  for (i = 0; i < length; i++) {
    int16_t value = code[i];
    if (value > 077777 || value < 0) {
      fprintf(stderr, "Warning: zeroing unassigned word at (%02o,%04o).\n",
              bank, (02000) + i);
      value = 0;
    }
    checksum = addAgc(checksum, value);
  }
  if ((checksum & 040000) == 0) {
    bugger = addAgc(bank, 077777 & ~checksum);
    if (verbose)
      printf("Checksum for bank %02o is %05o, MSB=0, bugger word is %05o.\n",
             bank, checksum, bugger);
  } else {
    bugger = addAgc(077777 & ~bank, 077777 & ~checksum);
    if (verbose)
      printf("Checksum for bank %02o is %05o, MSB=1, bugger word is %05o.\n",
             bank, checksum, bugger);
  }
  return (bugger);
}


x86 assembly (clang, -O0):
<generateBuggerWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d6 <generateBuggerWord+0xa6>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x7fff,-0x28(%rbp)
jg     1192 <generateBuggerWord+0x62>
cmpl   $0x0,-0x28(%rbp)
jge    11ba <generateBuggerWord+0x8a>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x24(%rbp),%ecx
add    $0x400,%ecx
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1030 <addAgc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <generateBuggerWord+0x31>
mov    -0x1c(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
jne    1222 <generateBuggerWord+0xf2>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
xor    $0xffffffff,%esi
and    $0x7fff,%esi
call   1030 <addAgc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     121d <generateBuggerWord+0xed>
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
jmp    1266 <generateBuggerWord+0x136>
mov    -0x8(%rbp),%edi
xor    $0xffffffff,%edi
and    $0x7fff,%edi
mov    -0x1c(%rbp),%esi
xor    $0xffffffff,%esi
and    $0x7fff,%esi
call   1030 <addAgc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1261 <generateBuggerWord+0x131>
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
jmp    1266 <generateBuggerWord+0x136>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateBuggerWord>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
test   %edx,%edx
jle    11ac <generateBuggerWord+0x7c>
mov    %rcx,%r13
mov    %ebx,0x4(%rsp)
mov    %edx,%ebx
xor    %r14d,%r14d
lea    0xea9(%rip),%r12
xor    %ebp,%ebp
jmp    1172 <generateBuggerWord+0x42>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <addAgc@plt>
mov    %eax,%ebp
add    $0x1,%r14
cmp    %r14,%rbx
je     119e <generateBuggerWord+0x6e>
mov    0x0(%r13,%r14,4),%esi
cmp    $0x8000,%esi
jb     1160 <generateBuggerWord+0x30>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0x400(%r14),%ecx
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <fprintf@plt>
xor    %esi,%esi
jmp    1160 <generateBuggerWord+0x30>
test   $0x4000,%ebp
jne    11d0 <generateBuggerWord+0xa0>
mov    0x4(%rsp),%ebx
jmp    11ae <generateBuggerWord+0x7e>
xor    %ebp,%ebp
mov    %ebp,%esi
not    %esi
and    $0x7fff,%esi
mov    %r15d,%edi
call   1030 <addAgc@plt>
mov    %eax,%r14d
test   %ebx,%ebx
je     1208 <generateBuggerWord+0xd8>
lea    0xe64(%rip),%rdi
jmp    11fb <generateBuggerWord+0xcb>
mov    %r15d,%edi
not    %edi
and    $0x7fff,%edi
mov    %ebp,%esi
not    %esi
and    $0x7fff,%esi
call   1030 <addAgc@plt>
mov    %eax,%r14d
cmpl   $0x0,0x4(%rsp)
je     1208 <generateBuggerWord+0xd8>
lea    0xe74(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"Warning: zeroing unassigned word at (%02o,%04o).\0A\00"
@.str.1 = [61 x i8] c"Checksum for bank %02o is %05o, MSB=0, bugger word is %05o.\0A\00"
@.str.2 = [61 x i8] c"Checksum for bank %02o is %05o, MSB=1, bugger word is %05o.\0A\00"
define i32 @generateBuggerWord(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %11
br label %13
13: ; preds = %38, %4
%14 = load i32, i32* %11
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = load i32*, i32** %8
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = icmp sgt i32 %23, 32767
br i1 %24, label %28, label %25
25: ; preds = %17
%26 = load i32, i32* %12
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25, %17
%29 = load i32, i32* @stderr
%30 = load i32, i32* %6
%31 = load i32, i32* %11
%32 = add nsw i32 1024, %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %32)
store i32 0, i32* %12
br label %34
34: ; preds = %28, %25
%35 = load i32, i32* %9
%36 = load i32, i32* %12
%37 = call i32 @addAgc(i32 %35, i32 %36)
store i32 %37, i32* %9
br label %38
38: ; preds = %34
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %13
41: ; preds = %13
%42 = load i32, i32* %9
%43 = and i32 %42, 16384
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %59
45: ; preds = %41
%46 = load i32, i32* %6
%47 = load i32, i32* %9
%48 = xor i32 %47, -1
%49 = and i32 32767, %48
%50 = call i32 @addAgc(i32 %46, i32 %49)
store i32 %50, i32* %10
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %45
%54 = load i32, i32* %6
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %55, i32 %56)
br label %58
58: ; preds = %53, %45
br label %75
59: ; preds = %41
%60 = load i32, i32* %6
%61 = xor i32 %60, -1
%62 = and i32 32767, %61
%63 = load i32, i32* %9
%64 = xor i32 %63, -1
%65 = and i32 32767, %64
%66 = call i32 @addAgc(i32 %62, i32 %65)
store i32 %66, i32* %10
%67 = load i32, i32* %5
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %59
%70 = load i32, i32* %6
%71 = load i32, i32* %9
%72 = load i32, i32* %10
%73 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %70, i32 %71, i32 %72)
br label %74
74: ; preds = %69, %59
br label %75
75: ; preds = %74, %58
%76 = load i32, i32* %10
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"Warning: zeroing unassigned word at (%02o,%04o).\0A\00"
@.str.1 = [61 x i8] c"Checksum for bank %02o is %05o, MSB=0, bugger word is %05o.\0A\00"
@.str.2 = [61 x i8] c"Checksum for bank %02o is %05o, MSB=1, bugger word is %05o.\0A\00"
define i32 @generateBuggerWord(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %27
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %19
%9 = phi i64 [ 0, %6 ], [ %22, %19 ]
%10 = phi i32 [ 0, %6 ], [ %21, %19 ]
%11 = getelementptr inbounds i32, i32* %3, i64 %9
%12 = load i32, i32* %11
%13 = icmp ugt i32 %12, 32767
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = trunc i64 %9 to i32
%17 = add i32 %16, 1024
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %17)
br label %19
19: ; preds = %8, %14
%20 = phi i32 [ 0, %14 ], [ %12, %8 ]
%21 = tail call i32 @addAgc(i32 %10, i32 %20)
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %8
24: ; preds = %19
%25 = and i32 %21, 16384
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %4, %24
%28 = phi i32 [ %21, %24 ], [ 0, %4 ]
%29 = and i32 %28, 32767
%30 = xor i32 %29, 32767
%31 = tail call i32 @addAgc(i32 %1, i32 %30)
%32 = icmp eq i32 %0, 0
br i1 %32, label %44, label %33
33: ; preds = %27
%34 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %28, i32 %31)
br label %44
35: ; preds = %24
%36 = and i32 %1, 32767
%37 = xor i32 %36, 32767
%38 = and i32 %21, 32767
%39 = xor i32 %38, 32767
%40 = tail call i32 @addAgc(i32 %37, i32 %39)
%41 = icmp eq i32 %0, 0
br i1 %41, label %44, label %42
42: ; preds = %35
%43 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %21, i32 %40)
br label %44
44: ; preds = %35, %42, %27, %33
%45 = phi i32 [ %31, %33 ], [ %31, %27 ], [ %40, %42 ], [ %40, %35 ]
ret i32 %45
}