#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 *, ...);
size_t strlen(unsigned char *);
void print_opcode(unsigned char *shellcode) {
  size_t len = strlen(shellcode);
  size_t counter = 0;
  for (int i = 0; i < len; i++) {
    if (counter == 7) {
      printf("\\x%02x\n", *(shellcode + i));
      counter = 0;
    } else {
      printf("\\x%02x", *(shellcode + i));
      counter++;
    }
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<print_opcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c1 <print_opcode+0xa1>
cmpq   $0x7,-0x18(%rbp)
jne    1188 <print_opcode+0x68>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
jmp    11ae <print_opcode+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b3 <print_opcode+0x93>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <print_opcode+0x28>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_opcode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %rax,%rax
je     1190 <print_opcode+0x60>
mov    %rax,%r13
lea    0xeae(%rip),%r15
lea    0xeaf(%rip),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1175 <print_opcode+0x45>
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
je     1190 <print_opcode+0x60>
movzbl (%r14,%rbx,1),%esi
cmp    $0x7,%rbp
je     1160 <print_opcode+0x30>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
jmp    116c <print_opcode+0x3c>
lea    0xe6f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"\\x%02x\0A\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
define void @print_opcode(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
store i64 0, i64* %4
store i32 0, i32* %5
br label %8
8: ; preds = %35, %1
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = load i64, i64* %3
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 7
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22)
store i64 0, i64* %4
br label %34
24: ; preds = %13
%25 = load i8*, i8** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i64, i64* %4
%33 = add i64 %32, 1
store i64 %33, i64* %4
br label %34
34: ; preds = %24, %16
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %8
38: ; preds = %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"\\x%02x\0A\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@str = [2 x i8] c"\0A\00"
define void @print_opcode(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %18, %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
6: ; preds = %1, %18
%7 = phi i64 [ %20, %18 ], [ 0, %1 ]
%8 = phi i64 [ %19, %18 ], [ 0, %1 ]
%9 = icmp eq i64 %8, 7
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
br i1 %9, label %13, label %15
13: ; preds = %6
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %18
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%17 = add i64 %8, 1
br label %18
18: ; preds = %13, %15
%19 = phi i64 [ 0, %13 ], [ %17, %15 ]
%20 = add nuw i64 %7, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %4, label %6
}