#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*/ printf(char *, ...);
void decompile(const char *s, unsigned int i) {
  unsigned char v;
  unsigned char par_count;
  for (unsigned int c = 0; c < i; c++) {
    v = (unsigned char)(*(s + c));
    printf("%04xh %02x ", c, v);
    if (par_count > 0) {
      par_count--;
      printf("%02xh ", v);
    } else {
      switch (v) {
      case 0xB4:
        printf("mov ah");
        par_count = 1;
        break;
      case 0xB9:
        printf("mov cx");
        par_count = 2;
        break;
      case 0xBA:
        printf("mov dx");
        par_count = 2;
        break;
      case 0xBB:
        printf("mov bx");
        par_count = 2;
        break;
      case 0xCC:
        printf("int 3");
        par_count = 0;
        break;
      case 0xCD:
        printf("int");
        par_count = 1;
        break;
      default:
        printf("%02xh", v);
        if (v >= 32) {
          printf(" \"%c\"", v);
        }
        break;
      }
    }
    printf("\r\n");
  }
}


x86 assembly (clang, -O0):
<decompile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    128d <decompile+0x17d>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0x14(%rbp),%esi
movzbl -0xd(%rbp),%edx
lea    0xf1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0xe(%rbp),%eax
cmp    $0x0,%eax
jle    1180 <decompile+0x70>
mov    -0xe(%rbp),%al
add    $0xff,%al
mov    %al,-0xe(%rbp)
movzbl -0xd(%rbp),%esi
lea    0xf00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <decompile+0x161>
movzbl -0xd(%rbp),%eax
add    $0xffffff4c,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x19,%eax
ja     1236 <decompile+0x126>
mov    -0x20(%rbp),%rax
lea    0xe5d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0xe(%rbp)
jmp    126c <decompile+0x15c>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x2,-0xe(%rbp)
jmp    126c <decompile+0x15c>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x2,-0xe(%rbp)
jmp    126c <decompile+0x15c>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x2,-0xe(%rbp)
jmp    126c <decompile+0x15c>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0xe(%rbp)
jmp    126c <decompile+0x15c>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x1,-0xe(%rbp)
jmp    126c <decompile+0x15c>
movzbl -0xd(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0xd(%rbp),%eax
cmp    $0x20,%eax
jl     1267 <decompile+0x157>
movzbl -0xd(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126c <decompile+0x15c>
jmp    1271 <decompile+0x161>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <decompile+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1240 <decompile+0x120>
mov    %rdi,%rbx
mov    %esi,%r13d
lea    0xf6d(%rip),%r15
xor    %r12d,%r12d
jmp    1175 <decompile+0x55>
lea    0xf3d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%r14b
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
add    $0x1,%r12
cmp    %r12,%r13
je     1240 <decompile+0x120>
movzbl (%rbx,%r12,1),%ebp
lea    0xee7(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14b,%r14b
je     11b0 <decompile+0x90>
add    $0xff,%r14b
lea    0xed7(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <decompile+0x40>
nopl   0x0(%rax,%rax,1)
lea    0x4c(%rbp),%eax
cmp    $0x19,%al
ja     11d3 <decompile+0xb3>
movzbl %al,%eax
lea    0xe3f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeaa(%rip),%rdi
jmp    1203 <decompile+0xe3>
xor    %r14d,%r14d
lea    0xec4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x20,%bpl
jb     1160 <decompile+0x40>
xor    %r14d,%r14d
lea    0xead(%rip),%rdi
jmp    119d <decompile+0x7d>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14b
jmp    1160 <decompile+0x40>
lea    0xe69(%rip),%rdi
jmp    114c <decompile+0x2c>
lea    0xe6b(%rip),%rdi
jmp    114c <decompile+0x2c>
xor    %r14d,%r14d
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <decompile+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%04xh %02x \00"
@.str.1 = [7 x i8] c"%02xh \00"
@.str.2 = [7 x i8] c"mov ah\00"
@.str.3 = [7 x i8] c"mov cx\00"
@.str.4 = [7 x i8] c"mov dx\00"
@.str.5 = [7 x i8] c"mov bx\00"
@.str.6 = [6 x i8] c"int 3\00"
@.str.7 = [4 x i8] c"int\00"
@.str.8 = [6 x i8] c"%02xh\00"
@.str.9 = [6 x i8] c" \22%c\22\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
define void @decompile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
br label %8
8: ; preds = %61, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %64
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32, i32* %7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = load i32, i32* %7
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %12
%26 = load i8, i8* %6
%27 = add i8 %26, -1
store i8 %27, i8* %6
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %59
31: ; preds = %12
%32 = load i8, i8* %5
%33 = zext i8 %32 to i32
switch i32 %33, label %46 [
i32 180, label %34
i32 185, label %36
i32 186, label %38
i32 187, label %40
i32 204, label %42
i32 205, label %44
]
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8 1, i8* %6
br label %58
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8 2, i8* %6
br label %58
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i8 2, i8* %6
br label %58
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i8 2, i8* %6
br label %58
42: ; preds = %31
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i8 0, i8* %6
br label %58
44: ; preds = %31
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i8 1, i8* %6
br label %58
46: ; preds = %31
%47 = load i8, i8* %5
%48 = zext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %48)
%50 = load i8, i8* %5
%51 = zext i8 %50 to i32
%52 = icmp sge i32 %51, 32
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i8, i8* %5
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53, %46
br label %58
58: ; preds = %57, %44, %42, %40, %38, %36, %34
br label %59
59: ; preds = %58, %25
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %61
61: ; preds = %59
%62 = load i32, i32* %7
%63 = add i32 %62, 1
store i32 %63, i32* %7
br label %8
64: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%04xh %02x \00"
@.str.1 = [7 x i8] c"%02xh \00"
@.str.2 = [7 x i8] c"mov ah\00"
@.str.3 = [7 x i8] c"mov cx\00"
@.str.4 = [7 x i8] c"mov dx\00"
@.str.5 = [7 x i8] c"mov bx\00"
@.str.6 = [6 x i8] c"int 3\00"
@.str.7 = [4 x i8] c"int\00"
@.str.8 = [6 x i8] c"%02xh\00"
@.str.9 = [6 x i8] c" \22%c\22\00"
@str = [2 x i8] c"\0D\00"
define void @decompile(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %37, %2
ret void
7: ; preds = %4, %37
%8 = phi i64 [ 0, %4 ], [ %40, %37 ]
%9 = phi i8 [ undef, %4 ], [ %38, %37 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = trunc i64 %8 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %12)
%15 = icmp eq i8 %9, 0
br i1 %15, label %19, label %16
16: ; preds = %7
%17 = add i8 %9, -1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %37
19: ; preds = %7
switch i8 %11, label %32 [
i8 -76, label %20
i8 -71, label %22
i8 -70, label %24
i8 -69, label %26
i8 -52, label %28
i8 -51, label %30
]
20: ; preds = %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %37
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %37
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %37
26: ; preds = %19
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %37
28: ; preds = %19
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %37
30: ; preds = %19
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %37
32: ; preds = %19
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %12)
%34 = icmp ugt i8 %11, 31
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %12)
br label %37
37: ; preds = %20, %22, %24, %26, %28, %30, %35, %32, %16
%38 = phi i8 [ %17, %16 ], [ 0, %35 ], [ 0, %32 ], [ 1, %30 ], [ 0, %28 ], [ 2, %26 ], [ 2, %24 ], [ 2, %22 ], [ 1, %20 ]
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%40 = add nuw nsw i64 %8, 1
%41 = icmp eq i64 %40, %5
br i1 %41, label %6, label %7
}