#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 snprintf(char *, int, char *, int, int, int);
int woodstock_disassemble_00(int, int, int, char *, int);
int woodstock_disassemble_arith(int, int, int, char *, int);
int woodstock_disassemble_branch(char *, int, int, char *, int);
int woodstock_disassemble_inst(int addr, int op1, int op2, char *buf, int len) {
  int l;
  l = snprintf(buf, len, "%o-%04o: %04o ", addr >> 12, addr & 07777, op1);
  buf += l;
  len -= l;
  if (len <= 0)
    return (0);
  switch (op1 & 3) {
  case 0:
    return (woodstock_disassemble_00(addr, op1, op2, buf, len));
  case 1:
    return (woodstock_disassemble_branch("jsb ", addr, op1, buf, len));
  case 2:
    return (woodstock_disassemble_arith(addr, op1, op2, buf, len));
  case 3:
    return (woodstock_disassemble_branch("if n/c go to ", addr, op1, buf, len));
  }
  return (0);
}


x86 assembly (clang, -O0):
<woodstock_disassemble_inst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%ecx
sar    $0xc,%ecx
mov    -0x8(%rbp),%r8d
and    $0xfff,%r8d
mov    -0xc(%rbp),%r9d
lea    0xe94(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11b6 <woodstock_disassemble_inst+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1264 <woodstock_disassemble_inst+0x124>
mov    -0xc(%rbp),%eax
and    $0x3,%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%eax
ja     125d <woodstock_disassemble_inst+0x11d>
mov    -0x28(%rbp),%rax
lea    0xe2c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1060 <woodstock_disassemble_00@plt>
mov    %eax,-0x4(%rbp)
jmp    1264 <woodstock_disassemble_inst+0x124>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe0f(%rip),%rdi
call   1040 <woodstock_disassemble_branch@plt>
mov    %eax,-0x4(%rbp)
jmp    1264 <woodstock_disassemble_inst+0x124>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1050 <woodstock_disassemble_arith@plt>
mov    %eax,-0x4(%rbp)
jmp    1264 <woodstock_disassemble_inst+0x124>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xdd4(%rip),%rdi
call   1040 <woodstock_disassemble_branch@plt>
mov    %eax,-0x4(%rbp)
jmp    1264 <woodstock_disassemble_inst+0x124>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<woodstock_disassemble_inst>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%ebp
mov    %edi,%ecx
sar    $0xc,%ecx
mov    %edi,%r8d
and    $0xfff,%r8d
lea    0xea4(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%r9d
call   1030 <snprintf@plt>
sub    %eax,%ebx
jle    11b3 <woodstock_disassemble_inst+0x73>
cltq
add    %rax,%r14
mov    %r15d,%eax
and    $0x3,%eax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <woodstock_disassemble_00@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5a(%rip),%rdi
jmp    11e9 <woodstock_disassemble_inst+0xa9>
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <woodstock_disassemble_arith@plt>
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <woodstock_disassemble_branch@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"%o-%04o: %04o \00"
@.str.1 = [5 x i8] c"jsb \00"
@.str.2 = [14 x i8] c"if n/c go to \00"
define i32 @woodstock_disassemble_inst(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i8*, i8** %10
%14 = load i32, i32* %11
%15 = load i32, i32* %7
%16 = ashr i32 %15, 12
%17 = load i32, i32* %7
%18 = and i32 %17, 4095
%19 = load i32, i32* %8
%20 = call i32 @snprintf(i8* %13, i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %19)
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = load i8*, i8** %10
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %10
%25 = load i32, i32* %12
%26 = load i32, i32* %11
%27 = sub nsw i32 %26, %25
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %5
store i32 0, i32* %6
br label %61
31: ; preds = %5
%32 = load i32, i32* %8
%33 = and i32 %32, 3
switch i32 %33, label %60 [
i32 0, label %34
i32 1, label %41
i32 2, label %47
i32 3, label %54
]
34: ; preds = %31
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = call i32 @woodstock_disassemble_00(i32 %35, i32 %36, i32 %37, i8* %38, i32 %39)
store i32 %40, i32* %6
br label %61
41: ; preds = %31
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = load i8*, i8** %10
%45 = load i32, i32* %11
%46 = call i32 @woodstock_disassemble_branch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43, i8* %44, i32 %45)
store i32 %46, i32* %6
br label %61
47: ; preds = %31
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = load i8*, i8** %10
%52 = load i32, i32* %11
%53 = call i32 @woodstock_disassemble_arith(i32 %48, i32 %49, i32 %50, i8* %51, i32 %52)
store i32 %53, i32* %6
br label %61
54: ; preds = %31
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = load i8*, i8** %10
%58 = load i32, i32* %11
%59 = call i32 @woodstock_disassemble_branch(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %56, i8* %57, i32 %58)
store i32 %59, i32* %6
br label %61
60: ; preds = %31
store i32 0, i32* %6
br label %61
61: ; preds = %60, %54, %47, %41, %34, %30
%62 = load i32, i32* %6
ret i32 %62
}

LLVM IR (-O2):
@.str = [15 x i8] c"%o-%04o: %04o \00"
@.str.1 = [5 x i8] c"jsb \00"
@.str.2 = [14 x i8] c"if n/c go to \00"
define i32 @woodstock_disassemble_inst(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = ashr i32 %0, 12
%7 = and i32 %0, 4095
%8 = tail call i32 @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, i32 %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %3, i64 %9
%11 = sub nsw i32 %4, %8
%12 = icmp slt i32 %11, 1
br i1 %12, label %24, label %13
13: ; preds = %5
%14 = and i32 %1, 3
switch i32 %14, label %23 [
i32 0, label %15
i32 1, label %17
i32 2, label %19
i32 3, label %21
]
15: ; preds = %13
%16 = tail call i32 @woodstock_disassemble_00(i32 %0, i32 %1, i32 %2, i8* %10, i32 %11)
br label %24
17: ; preds = %13
%18 = tail call i32 @woodstock_disassemble_branch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1, i8* %10, i32 %11)
br label %24
19: ; preds = %13
%20 = tail call i32 @woodstock_disassemble_arith(i32 %0, i32 %1, i32 %2, i8* %10, i32 %11)
br label %24
21: ; preds = %13
%22 = tail call i32 @woodstock_disassemble_branch(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1, i8* %10, i32 %11)
br label %24
23: ; preds = %13
unreachable
24: ; preds = %5, %21, %19, %17, %15
%25 = phi i32 [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ 0, %5 ]
ret i32 %25
}