#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 /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
int nut_disassemble_short_branch(int addr, int op1, char *buf, int len) {
  int offset, cond, target;
  offset = (op1 >> 3) & 0x3f;
  if (op1 & 0x200)
    offset -= 64;
  target = addr + offset;
  cond = (op1 >> 2) & 1;
  snprintf(buf, len, "?%s goto %05o", cond ? "c " : "nc", target);
  return (1);
}


x86 assembly (clang, -O0):
<nut_disassemble_short_branch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x3,%eax
and    $0x3f,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0x200,%eax
cmp    $0x0,%eax
je     114b <nut_disassemble_short_branch+0x3b>
mov    -0x18(%rbp),%eax
sub    $0x40,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x2,%eax
and    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xea0(%rip),%rcx
lea    0xe96(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%rcx
mov    -0x20(%rbp),%r8d
lea    0xe76(%rip),%rdx
call   1030 <snprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nut_disassemble_short_branch>:
push   %rax
mov    %rdx,%r9
mov    %esi,%r8d
shr    $0x3,%r8d
and    $0x3f,%r8d
mov    %esi,%eax
shl    $0x16,%eax
sar    $0x1f,%eax
and    $0xffffffc0,%eax
add    %edi,%r8d
add    %eax,%r8d
test   $0x4,%sil
lea    0xed6(%rip),%rdx
lea    0xecc(%rip),%rax
cmove  %rdx,%rax
lea    0xeb3(%rip),%rdx
mov    %r9,%rdi
mov    %ecx,%esi
mov    %rax,%rcx
call   1030 <snprintf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"?%s goto %05o\00"
@.str.1 = [3 x i8] c"c \00"
@.str.2 = [3 x i8] c"nc\00"
define i32 @nut_disassemble_short_branch(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = ashr i32 %12, 3
%14 = and i32 %13, 63
store i32 %14, i32* %9
%15 = load i32, i32* %6
%16 = and i32 %15, 512
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* %9
%20 = sub nsw i32 %19, 64
store i32 %20, i32* %9
br label %21
21: ; preds = %18, %4
%22 = load i32, i32* %5
%23 = load i32, i32* %9
%24 = add nsw i32 %22, %23
store i32 %24, i32* %11
%25 = load i32, i32* %6
%26 = ashr i32 %25, 2
%27 = and i32 %26, 1
store i32 %27, i32* %10
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = load i32, i32* %10
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%34 = load i32, i32* %11
%35 = call i32 @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %33, i32 %34)
ret i32 1
}

LLVM IR (-O2):
@.str = [14 x i8] c"?%s goto %05o\00"
@.str.1 = [3 x i8] c"c \00"
@.str.2 = [3 x i8] c"nc\00"
define i32 @nut_disassemble_short_branch(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = lshr i32 %1, 3
%6 = and i32 %5, 63
%7 = and i32 %1, 512
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 0, i32 -64
%10 = add i32 %6, %0
%11 = add i32 %10, %9
%12 = and i32 %1, 4
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%15 = tail call i32 @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %11)
ret i32 1
}