void goto_test() {
  int i;
  static void *label_table[3] = {&&label1, &&label2, &&label3};
  printf("goto:\n");
  i = 0;
s_loop:
  if (i >= 10)
    goto s_end;
  printf("%d", i);
  i++;
  goto s_loop;
s_end:
  printf("\n");
  for (i = 0; i < 3; i++) {
    goto *label_table[i];
  label1:
    printf("label1\n");
    goto next;
  label2:
    printf("label2\n");
    goto next;
  label3:
    printf("label3\n");
  next:;
  }
}


x86 assembly (clang, -O0):
<goto_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jl     113c <goto_test+0x2c>
jmp    115b <goto_test+0x4b>
mov    -0x4(%rbp),%esi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112d <goto_test+0x1d>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    11d9 <goto_test+0xc9>
movslq -0x4(%rbp),%rcx
lea    0x2eab(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
jmp    11df <goto_test+0xcf>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <goto_test+0xb6>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <goto_test+0xb6>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cb <goto_test+0xbb>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1170 <goto_test+0x60>
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
jmp    *%rax

x86 assembly (clang, -O2):
<goto_test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb4(%rip),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x2c0e(%rip),%r14
lea    0xe1e(%rip),%r15
lea    0xe10(%rip),%r12
lea    0xe02(%rip),%r13
jmp    1222 <goto_test+0xf2>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <puts@plt>
add    $0x8,%rbx
cmp    $0x18,%rbx
je     1235 <goto_test+0x105>
jmp    *(%rbx,%r14,1)
mov    %r12,%rdi
jmp    1213 <goto_test+0xe3>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
jmp    1213 <goto_test+0xe3>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@goto_test.label_table = internal global [3 x i8*] [i8* blockaddress(@goto_test, %22), i8* blockaddress(@goto_test, %24), i8* blockaddress(@goto_test, %26)]
@.str = [7 x i8] c"goto:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [8 x i8] c"label1\0A\00"
@.str.4 = [8 x i8] c"label2\0A\00"
@.str.5 = [8 x i8] c"label3\0A\00"
define void @goto_test() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %3
3: ; preds = %7, %0
%4 = load i32, i32* %1
%5 = icmp sge i32 %4, 10
br i1 %5, label %6, label %7
6: ; preds = %3
br label %12
7: ; preds = %3
%8 = load i32, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
br label %3
12: ; preds = %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %14
14: ; preds = %29, %12
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* @goto_test.label_table, i64 0, i64 %19
%21 = load i8*, i8** %20
br label %33
22: ; preds = %33
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %28
24: ; preds = %33
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %28
26: ; preds = %33
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %24, %22
br label %29
29: ; preds = %28
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %14
32: ; preds = %14
ret void
33: ; preds = %17
%34 = phi i8* [ %21, %17 ]
indirectbr i8* %34, [label %22, label %24, label %26]
}

LLVM IR (-O2):
@goto_test.label_table = internal unnamed_addr constant [3 x i8*] [i8* blockaddress(@goto_test, %19), i8* blockaddress(@goto_test, %17), i8* blockaddress(@goto_test, %18)]
@.str.1 = [3 x i8] c"%d\00"
@str = [6 x i8] c"goto:\00"
@str.6 = [7 x i8] c"label3\00"
@str.7 = [7 x i8] c"label2\00"
@str.8 = [7 x i8] c"label1\00"
define void @goto_test() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 4)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 6)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 7)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 8)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 9)
%12 = tail call i32 @putchar(i32 10)
br label %13
13: ; preds = %0, %19
%14 = phi i64 [ 0, %0 ], [ %22, %19 ]
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* @goto_test.label_table, i64 0, i64 %14
%16 = load i8*, i8** %15
indirectbr i8* %16, [label %19, label %17, label %18]
17: ; preds = %13
br label %19
18: ; preds = %13
br label %19
19: ; preds = %13, %17, %18
%20 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.7, i64 0, i64 0), %17 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0), %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0), %13 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, 3
br i1 %23, label %24, label %13
24: ; preds = %19
ret void
}