#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ arch_bfdDisasm(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                  size_t, char *);
size_t arch_getProcMem(int /*<<< orphan*/, int /*<<< orphan*/ *, int,
                       int /*<<< orphan*/);
int /*<<< orphan*/ isprint(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void arch_getInstrStr(pid_t pid, uint64_t pc,
                      uint64_t status_reg __attribute__((unused)),
                      size_t pcRegSz __attribute__((unused)), char *instr) {
  uint8_t buf[16];
  size_t memsz;
  snprintf(instr, 64, "%s", "[UNKNOWN]");
  if ((memsz = arch_getProcMem(pid, buf, sizeof(buf), pc)) == 0) {
    snprintf(instr, 64, "%s", "[NOT_MMAPED]");
    return;
  }
  arch_bfdDisasm(pid, buf, memsz, instr);
  for (int x = 0; instr[x] && x < 64; x++) {
    if (instr[x] == '/' || instr[x] == '\\' || isspace(instr[x]) ||
        !isprint(instr[x])) {
      instr[x] = '_';
    }
  }
  return;
}


x86 assembly (clang, -O0):
<arch_getInstrStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x40,%esi
lea    0xe87(%rip),%rdx
lea    0xe83(%rip),%rcx
call   1040 <snprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x8(%rbp),%ecx
mov    $0x40,%edx
call   1050 <arch_getProcMem@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11c8 <arch_getInstrStr+0x78>
mov    -0x20(%rbp),%rdi
mov    $0x40,%esi
lea    0xe49(%rip),%rdx
lea    0xe4f(%rip),%rcx
call   1040 <snprintf@plt>
jmp    129a <arch_getInstrStr+0x14a>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <arch_bfdDisasm@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x6d(%rbp)
je     1207 <arch_getInstrStr+0xb7>
cmpl   $0x40,-0x6c(%rbp)
setl   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    1217 <arch_getInstrStr+0xc7>
jmp    1295 <arch_getInstrStr+0x145>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1276 <arch_getInstrStr+0x126>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     1276 <arch_getInstrStr+0x126>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
jne    1276 <arch_getInstrStr+0x126>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
jne    1282 <arch_getInstrStr+0x132>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1287 <arch_getInstrStr+0x137>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11e3 <arch_getInstrStr+0x93>
jmp    129a <arch_getInstrStr+0x14a>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arch_getInstrStr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %r8,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe99(%rip),%rdx
lea    0xe95(%rip),%rcx
mov    %r8,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x40,%edx
mov    %r14d,%ecx
call   1050 <arch_getProcMem@plt>
test   %rax,%rax
je     11f0 <arch_getInstrStr+0xa0>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <arch_bfdDisasm@plt>
mov    (%rbx),%al
test   %al,%al
je     120b <arch_getInstrStr+0xbb>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    $0x2f,%al
je     11c5 <arch_getInstrStr+0x75>
cmp    $0x5c,%al
je     11c5 <arch_getInstrStr+0x75>
movsbl %al,%edi
call   1060 <isspace@plt>
test   %rax,%rax
je     11e1 <arch_getInstrStr+0x91>
movb   $0x5f,(%rbx,%rbp,1)
movzbl 0x1(%rbx,%rbp,1),%eax
test   %al,%al
je     120b <arch_getInstrStr+0xbb>
lea    0x1(%rbp),%rcx
cmp    $0x3f,%rbp
mov    %rcx,%rbp
jb     11b0 <arch_getInstrStr+0x60>
jmp    120b <arch_getInstrStr+0xbb>
movsbl (%rbx,%rbp,1),%edi
call   1070 <isprint@plt>
test   %eax,%eax
jne    11c9 <arch_getInstrStr+0x79>
jmp    11c5 <arch_getInstrStr+0x75>
lea    0xe09(%rip),%rdx
lea    0xe0f(%rip),%rcx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"[UNKNOWN]\00"
@.str.2 = [13 x i8] c"[NOT_MMAPED]\00"
define void @arch_getInstrStr(i32 %0, i32 %1, i32 %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca [16 x i32]
%12 = alloca i64
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i8* %4, i8** %10
%14 = load i8*, i8** %10
%15 = call i32 @snprintf(i8* %14, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%18 = load i32, i32* %7
%19 = call i64 @arch_getProcMem(i32 %16, i32* %17, i32 64, i32 %18)
store i64 %19, i64* %12
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %5
%22 = load i8*, i8** %10
%23 = call i32 @snprintf(i8* %22, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %85
24: ; preds = %5
%25 = load i32, i32* %6
%26 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%27 = load i64, i64* %12
%28 = load i8*, i8** %10
%29 = call i32 @arch_bfdDisasm(i32 %25, i32* %26, i64 %27, i8* %28)
store i32 0, i32* %13
br label %30
30: ; preds = %81, %24
%31 = load i8*, i8** %10
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* %13
%40 = icmp slt i32 %39, 64
br label %41
41: ; preds = %38, %30
%42 = phi i1 [ false, %30 ], [ %40, %38 ]
br i1 %42, label %43, label %84
43: ; preds = %41
%44 = load i8*, i8** %10
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 47
br i1 %50, label %75, label %51
51: ; preds = %43
%52 = load i8*, i8** %10
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 92
br i1 %58, label %75, label %59
59: ; preds = %51
%60 = load i8*, i8** %10
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = call i64 @isspace(i8 signext %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %75, label %67
67: ; preds = %59
%68 = load i8*, i8** %10
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = call i32 @isprint(i8 signext %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %67, %59, %51, %43
%76 = load i8*, i8** %10
%77 = load i32, i32* %13
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
store i8 95, i8* %79
br label %80
80: ; preds = %75, %67
br label %81
81: ; preds = %80
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 1
store i32 %83, i32* %13
br label %30
84: ; preds = %41
br label %85
85: ; preds = %84, %21
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [10 x i8] c"[UNKNOWN]\00"
@.str.2 = [13 x i8] c"[NOT_MMAPED]\00"
define void @arch_getInstrStr(i32 %0, i32 %1, i32 %2, i64 %3, i8* %4) {
%6 = alloca [16 x i32]
%7 = bitcast [16 x i32]* %6 to i8*
%8 = tail call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%10 = call i64 @arch_getProcMem(i32 %0, i32* %9, i32 64, i32 %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %37
14: ; preds = %5
%15 = call i32 @arch_bfdDisasm(i32 %0, i32* %9, i64 %10, i8* %4)
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %14, %30
%19 = phi i64 [ %31, %30 ], [ 0, %14 ]
%20 = phi i8 [ %33, %30 ], [ %16, %14 ]
%21 = phi i8* [ %32, %30 ], [ %4, %14 ]
switch i8 %20, label %22 [
i8 47, label %29
i8 92, label %29
]
22: ; preds = %18
%23 = call i64 @isspace(i8 signext %20)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i8, i8* %21
%27 = call i32 @isprint(i8 signext %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %18, %18, %25, %22
store i8 95, i8* %21
br label %30
30: ; preds = %25, %29
%31 = add nuw nsw i64 %19, 1
%32 = getelementptr inbounds i8, i8* %4, i64 %31
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
%35 = icmp ult i64 %19, 63
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %18, label %37
37: ; preds = %30, %14, %12
ret void
}