int main(void) {
  int i;
  void *opcode;
  unsigned int length;
  for (i = 0, opcode = main; i < 10; i++) {
    length = length_disasm(opcode);
    opcode = (char *)opcode + length;
    printf("%d\n", length);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1186 <main+0x66>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <length_disasm@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2ebc(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%r15d
add    %r14,%r15
lea    0xebd(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%ebx
add    %r15,%rbx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%r15d
add    %rbx,%r15
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%ebx
add    %r15,%rbx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%r15d
add    %rbx,%r15
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%ebx
add    %r15,%rbx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%r15d
add    %rbx,%r15
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%ebx
add    %r15,%rbx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %eax,%r15d
add    %rbx,%r15
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <length_disasm@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i8* bitcast (i32 ()* @main to i8*), i8** %3
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %9)
store i32 %10, i32* %4
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8* %14, i8** %3
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %8
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %5
20: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* bitcast (i32 ()* @main to i8*))
%2 = zext i32 %1 to i64
%3 = getelementptr inbounds i8, i8* bitcast (i32 ()* @main to i8*), i64 %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %3)
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %7)
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%13 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %11)
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%17 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %15)
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%21 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %19)
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%25 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %23)
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%29 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %27)
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
%33 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %31)
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
%37 = tail call i32 (i8*, ...) bitcast (i32 (...)* @length_disasm to i32 (i8*, ...)*)(i8* %35)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
ret i32 0
}