#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 dis51_inst1(unsigned char const *, int /*<<< orphan*/, int *);
int dis51_inst2(char *, unsigned char const *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int dis51_udis(char *str, const unsigned char *bytes, int len,
               unsigned long long seek) {
  int ptr, type;
  ptr = dis51_inst1(bytes, 0, &type);
  if (ptr == -1) {
    sprintf(str, "(invalid instruction)");
    return -1;
  }
  return dis51_inst2(str, bytes, 0);
}


x86 assembly (clang, -O0):
<dis51_udis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
lea    -0x30(%rbp),%rdx
call   1030 <dis51_inst1@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    117f <dis51_udis+0x4f>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <dis51_udis+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <dis51_inst2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dis51_udis>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%rdx
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <dis51_inst1@plt>
cmp    $0xffffffff,%eax
je     114d <dis51_udis+0x2d>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <dis51_inst2@plt>
jmp    116b <dis51_udis+0x4b>
movups 0xeac(%rip),%xmm0
movups %xmm0,(%r14)
movabs $0x296e6f69746375,%rax
mov    %rax,0xe(%r14)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"(invalid instruction)\00"
define i32 @dis51_udis(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%12 = load i8*, i8** %7
%13 = call i32 @dis51_inst1(i8* %12, i32 0, i32* %11)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %23
19: ; preds = %4
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = call i32 @dis51_inst2(i8* %20, i8* %21, i32 0)
store i32 %22, i32* %5
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@.str = [22 x i8] c"(invalid instruction)\00"
define i32 @dis51_udis(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @dis51_inst1(i8* %1, i32 0, i32* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %4
br label %12
10: ; preds = %4
%11 = call i32 @dis51_inst2(i8* %0, i8* %1, i32 0)
br label %12
12: ; preds = %10, %9
%13 = phi i32 [ -1, %9 ], [ %11, %10 ]
ret i32 %13
}