void local_label_test(void) {
  int a;
  goto l1;
l2:
  a = 1 + ({
        __label__ l1, l2, l3, l4;
        goto l1;
      l4:
        printf("aa1\n");
        goto l3;
      l2:
        printf("aa3\n");
        goto l4;
      l1:
        printf("aa2\n");
        goto l2;
      l3:;
        1;
      });
  printf("a=%d\n", a);
  return;
l4:
  printf("bb1\n");
  goto l2;
l1:
  printf("bb2\n");
  goto l4;
}


x86 assembly (clang, -O0):
<local_label_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
jmp    1195 <local_label_test+0x85>
jmp    1148 <local_label_test+0x38>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115b <local_label_test+0x4b>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1122 <local_label_test+0x12>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1135 <local_label_test+0x25>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    111d <local_label_test+0xd>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <local_label_test+0x72>

x86 assembly (clang, -O2):
<local_label_test>:
push   %rax
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
pop    %rcx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"aa1\0A\00"
@.str.1 = [5 x i8] c"aa3\0A\00"
@.str.2 = [5 x i8] c"aa2\0A\00"
@.str.3 = [6 x i8] c"a=%d\0A\00"
@.str.4 = [5 x i8] c"bb1\0A\00"
@.str.5 = [5 x i8] c"bb2\0A\00"
define void @local_label_test() {
%1 = alloca i32
%2 = alloca i32
br label %17
3: ; preds = %15
br label %8
4: ; preds = %6
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %8
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %4
8: ; preds = %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %6
10: ; preds = %4
store i32 1, i32* %2
%11 = load i32, i32* %2
%12 = add nsw i32 1, %11
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %13)
ret void
15: ; preds = %17
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %3
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %15
}

LLVM IR (-O2):
@.str.3 = [6 x i8] c"a=%d\0A\00"
@str = [4 x i8] c"bb2\00"
@str.6 = [4 x i8] c"bb1\00"
@str.7 = [4 x i8] c"aa2\00"
@str.8 = [4 x i8] c"aa3\00"
@str.9 = [4 x i8] c"aa1\00"
define void @local_label_test() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.6, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 2)
ret void
}