#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 print_arch_code(void *address, size_t seg_size) {
  char *text = (char *)address;
  for (int i = 0; i < seg_size;) {
    int size = 1;
    for (int j = 0; j < size; j++) {
      if (j == 0) {
        switch (text[i + j]) {
        case (char)0x68:
        case (char)0x55:
        case (char)0xE9:
        case (char)0xE8:
          size = 5;
          break;
        case (char)0xC8:
          size = 4;
          break;
        case (char)0x83:
        case (char)0xFF:
          size = 3;
          break;
        case (char)0xC9:
          size = 2;
          break;
        }
      }
      unsigned int value = text[i + j];
      value = (value << 24) >> 24;
      printf("%02X ", value);
    }
    i += size;
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_arch_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1279 <print_arch_code+0x169>
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    125d <print_arch_code+0x14d>
cmpl   $0x0,-0x24(%rbp)
jne    121e <print_arch_code+0x10e>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xffffff83,%eax
je     1206 <print_arch_code+0xf6>
jmp    1185 <print_arch_code+0x75>
mov    -0x2c(%rbp),%eax
sub    $0xffffffc8,%eax
je     11fa <print_arch_code+0xea>
jmp    1196 <print_arch_code+0x86>
mov    -0x2c(%rbp),%eax
sub    $0xffffffc9,%eax
je     1212 <print_arch_code+0x102>
jmp    11a7 <print_arch_code+0x97>
mov    -0x2c(%rbp),%eax
add    $0x18,%eax
sub    $0x2,%eax
jb     11ee <print_arch_code+0xde>
jmp    11bb <print_arch_code+0xab>
mov    -0x2c(%rbp),%eax
sub    $0xffffffff,%eax
je     1206 <print_arch_code+0xf6>
jmp    11cc <print_arch_code+0xbc>
mov    -0x2c(%rbp),%eax
sub    $0x55,%eax
je     11ee <print_arch_code+0xde>
jmp    11dd <print_arch_code+0xcd>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
jne    1219 <print_arch_code+0x109>
jmp    11ee <print_arch_code+0xde>
movl   $0x5,-0x20(%rbp)
jmp    1219 <print_arch_code+0x109>
movl   $0x4,-0x20(%rbp)
jmp    1219 <print_arch_code+0x109>
movl   $0x3,-0x20(%rbp)
jmp    1219 <print_arch_code+0x109>
movl   $0x2,-0x20(%rbp)
jmp    121e <print_arch_code+0x10e>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x18,%eax
shr    $0x18,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114b <print_arch_code+0x3b>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112f <print_arch_code+0x1f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_arch_code>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
test   %rsi,%rsi
je     1243 <print_arch_code+0x123>
mov    %rdi,%r14
lea    0xeba(%rip),%rbx
xor    %ecx,%ecx
xor    %r13d,%r13d
mov    %rdi,0x8(%rsp)
jmp    118b <print_arch_code+0x6b>
movzbl (%r14,%rax,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12d
nopw   0x0(%rax,%rax,1)
add    %r12d,%r13d
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq %r13d,%rcx
cmp    0x10(%rsp),%rcx
jae    1243 <print_arch_code+0x123>
movslq %r13d,%rax
movsbl (%r14,%rcx,1),%ecx
cmp    $0xffffffe7,%ecx
jle    11b0 <print_arch_code+0x90>
cmp    $0x54,%ecx
jg     11d0 <print_arch_code+0xb0>
lea    0x18(%rcx),%edx
cmp    $0x2,%edx
jb     11de <print_arch_code+0xbe>
cmp    $0xffffffff,%ecx
je     11f0 <print_arch_code+0xd0>
jmp    1152 <print_arch_code+0x32>
nopl   0x0(%rax)
cmp    $0xffffff83,%ecx
je     11f0 <print_arch_code+0xd0>
cmp    $0xffffffc8,%ecx
je     11f8 <print_arch_code+0xd8>
mov    $0x2,%r12d
cmp    $0xffffffc9,%ecx
je     1200 <print_arch_code+0xe0>
jmp    1152 <print_arch_code+0x32>
nopw   0x0(%rax,%rax,1)
cmp    $0x55,%ecx
je     11de <print_arch_code+0xbe>
cmp    $0x68,%ecx
jne    1152 <print_arch_code+0x32>
mov    $0x5,%r12d
jmp    1200 <print_arch_code+0xe0>
cs nopw 0x0(%rax,%rax,1)
mov    $0x3,%r12d
jmp    1200 <print_arch_code+0xe0>
mov    $0x4,%r12d
xchg   %ax,%ax
lea    (%r14,%rax,1),%rbp
movzbl (%r14,%rax,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%r14d
mov    $0x1,%r15d
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r15,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r14,%r15
jb     1220 <print_arch_code+0x100>
mov    0x8(%rsp),%r14
jmp    1170 <print_arch_code+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_arch_code(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = load i8*, i8** %3
store i8* %10, i8** %5
store i32 0, i32* %6
br label %11
11: ; preds = %55, %2
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %60
16: ; preds = %11
store i32 1, i32* %7
store i32 0, i32* %8
br label %17
17: ; preds = %52, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %55
21: ; preds = %17
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = load i32, i32* %8
%28 = add nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
switch i32 %32, label %37 [
i32 104, label %33
i32 85, label %33
i32 -23, label %33
i32 -24, label %33
i32 -56, label %34
i32 -125, label %35
i32 -1, label %35
i32 -55, label %36
]
33: ; preds = %24, %24, %24, %24
store i32 5, i32* %7
br label %37
34: ; preds = %24
store i32 4, i32* %7
br label %37
35: ; preds = %24, %24
store i32 3, i32* %7
br label %37
36: ; preds = %24
store i32 2, i32* %7
br label %37
37: ; preds = %24, %36, %35, %34, %33
br label %38
38: ; preds = %37, %21
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = add nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = shl i32 %47, 24
%49 = lshr i32 %48, 24
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %38
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %17
55: ; preds = %17
%56 = load i32, i32* %7
%57 = load i32, i32* %6
%58 = add nsw i32 %57, %56
store i32 %58, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
60: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
define void @print_arch_code(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %26, label %4
4: ; preds = %2, %27
%5 = phi i64 [ %31, %27 ], [ 0, %2 ]
%6 = phi i32 [ %29, %27 ], [ 0, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %14 [
i32 104, label %13
i32 85, label %13
i32 -23, label %13
i32 -24, label %13
i32 -56, label %12
i32 -125, label %11
i32 -1, label %11
i32 -55, label %19
]
11: ; preds = %4, %4
br label %19
12: ; preds = %4
br label %19
13: ; preds = %4, %4, %4, %4
br label %19
14: ; preds = %4
%15 = getelementptr inbounds i8, i8* %0, i64 %7
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %27
19: ; preds = %4, %13, %12, %11
%20 = phi i32 [ 3, %11 ], [ 4, %12 ], [ 5, %13 ], [ 2, %4 ]
%21 = getelementptr inbounds i8, i8* %0, i64 %7
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = zext i32 %20 to i64
br label %33
26: ; preds = %27, %2
ret void
27: ; preds = %33, %14
%28 = phi i32 [ 1, %14 ], [ %20, %33 ]
%29 = add nsw i32 %28, %6
%30 = tail call i32 @putchar(i32 10)
%31 = sext i32 %29 to i64
%32 = icmp ult i64 %31, %1
br i1 %32, label %4, label %26
33: ; preds = %19, %33
%34 = phi i64 [ 1, %19 ], [ %40, %33 ]
%35 = add nsw i64 %34, %7
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = add nuw nsw i64 %34, 1
%41 = icmp ult i64 %40, %25
br i1 %41, label %33, label %27
}