void print_code_segment(const int *code, int length) {
  int i;
  int as_arg = 0;
  int as_jump = 0;
  printf(" Code:\n");
  for (i = 0; i < length; i++) {
    if (!as_arg) {
      printf("%5d: %s\n", i, opcode_to_string(code[i]));
      if (has_runtime_arg(code[i])) {
        as_arg = 1;
      }
      if (is_a_jump(code[i])) {
        as_jump = 1;
      }
    } else {
      printf(as_jump ? "%5d: #%d\n" : "%5d: %d\n", i, code[i]);
      as_arg = 0;
      as_jump = 0;
    }
  }
}


x86 assembly (clang, -O0):
<print_code_segment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124a <print_code_segment+0x10a>
cmpl   $0x0,-0x14(%rbp)
jne    11fc <print_code_segment+0xbc>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x0,%al
call   1060 <opcode_to_string@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x0,%al
call   1050 <has_runtime_arg@plt>
cmp    $0x0,%eax
je     11d5 <print_code_segment+0x95>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x0,%al
call   1030 <is_a_jump@plt>
cmp    $0x0,%eax
je     11f7 <print_code_segment+0xb7>
movl   $0x1,-0x18(%rbp)
jmp    1237 <print_code_segment+0xf7>
mov    -0x18(%rbp),%ecx
lea    0xe15(%rip),%rdi
lea    0xe04(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    123c <print_code_segment+0xfc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <print_code_segment+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_code_segment>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    1209 <print_code_segment+0xb9>
mov    %ebx,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    118c <print_code_segment+0x3c>
mov    %r14b,%r13b
add    $0x1,%rbx
cmp    %rbx,%r12
je     1209 <print_code_segment+0xb9>
test   %r13d,%r13d
jne    11e0 <print_code_segment+0x90>
mov    (%r15,%rbx,4),%edi
xor    %eax,%eax
call   1070 <opcode_to_string@plt>
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15,%rbx,4),%edi
xor    %eax,%eax
call   1060 <has_runtime_arg@plt>
xor    %r13d,%r13d
test   %eax,%eax
setne  %r14b
mov    (%r15,%rbx,4),%edi
xor    %eax,%eax
call   1040 <is_a_jump@plt>
test   %eax,%eax
je     1180 <print_code_segment+0x30>
mov    $0x1,%ebp
jmp    1180 <print_code_segment+0x30>
nopl   0x0(%rax,%rax,1)
lea    0xe2c(%rip),%rdi
test   %ebp,%ebp
je     11f2 <print_code_segment+0xa2>
lea    0xe17(%rip),%rdi
mov    (%r15,%rbx,4),%edx
xor    %r13d,%r13d
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    1183 <print_code_segment+0x33>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%5d: %s\0A\00"
@.str.2 = [10 x i8] c"%5d: #%d\0A\00"
@.str.3 = [9 x i8] c"%5d: %d\0A\00"
@str = [7 x i8] c" Code:\00"
define void @print_code_segment(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %38
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %33
%8 = phi i64 [ 0, %5 ], [ %36, %33 ]
%9 = phi i32 [ 0, %5 ], [ %35, %33 ]
%10 = phi i32 [ 0, %5 ], [ %34, %33 ]
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %0, i64 %8
%14 = load i32, i32* %13
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @opcode_to_string to i32 (i32, ...)*)(i32 %14)
%16 = trunc i64 %8 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %15)
%18 = load i32, i32* %13
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @has_runtime_arg to i32 (i32, ...)*)(i32 %18)
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i32
%22 = load i32, i32* %13
%23 = tail call i32 (i32, ...) bitcast (i32 (...)* @is_a_jump to i32 (i32, ...)*)(i32 %22)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 %9, i32 1
br label %33
26: ; preds = %7
%27 = icmp eq i32 %9, 0
%28 = select i1 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%29 = getelementptr inbounds i32, i32* %0, i64 %8
%30 = load i32, i32* %29
%31 = trunc i64 %8 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %28, i32 %31, i32 %30)
br label %33
33: ; preds = %12, %26
%34 = phi i32 [ 0, %26 ], [ %21, %12 ]
%35 = phi i32 [ 0, %26 ], [ %25, %12 ]
%36 = add nuw nsw i64 %8, 1
%37 = icmp eq i64 %36, %6
br i1 %37, label %38, label %7
38: ; preds = %33, %2
ret void
}