__attribute__((always_, no_instrument_function)) int range(int b, int e) {
  for (int i = b; i != e; i += (b < e ? 1 : -1))
    if (__yield_setjmp(__builtin_return_address(0), __func__) == 42)
      return i;
    else
      __yield_postjump();
  ;
  return (int){0};
}


x86 assembly (clang, -O0):
<range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1192 <range+0x72>
mov    0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1030 <__yield_setjmp@plt>
cmp    $0x2a,%eax
jne    1166 <range+0x46>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <range+0x7f>
mov    $0x0,%al
call   1040 <__yield_postjump@plt>
jmp    1172 <range+0x52>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%esi
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <range+0x14>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    %esi,%edi
je     1185 <range+0x65>
mov    %esi,%r12d
mov    %edi,%ebx
mov    0x38(%rsp),%r14
setl   %al
movzbl %al,%eax
lea    (%rax,%rax,1),%r13d
add    $0xffffffff,%r13d
lea    0xeb0(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <__yield_setjmp@plt>
cmp    $0x2a,%eax
je     1183 <range+0x63>
xor    %eax,%eax
call   1040 <__yield_postjump@plt>
add    %r13d,%ebx
cmp    %ebx,%r12d
jne    1160 <range+0x40>
jmp    1185 <range+0x65>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__func__.range = [6 x i8] c"range\00"
define i32 @range(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
store i32 %8, i32* %6
br label %9
9: ; preds = %22, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = call i8* @llvm.returnaddress(i32 0)
%15 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @__yield_setjmp to i32 (i8*, i8*, ...)*)(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.range, i64 0, i64 0))
%16 = icmp eq i32 %15, 42
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %32
19: ; preds = %13
%20 = call i32 (...) @__yield_postjump()
br label %21
21: ; preds = %19
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 1, i32 -1
%28 = load i32, i32* %6
%29 = add nsw i32 %28, %27
store i32 %29, i32* %6
br label %9
30: ; preds = %9
store i32 0, i32* %7
%31 = load i32, i32* %7
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %17
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@__func__.range = [6 x i8] c"range\00"
define i32 @range(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, %1
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = tail call i8* @llvm.returnaddress(i32 0)
%6 = icmp slt i32 %0, %1
%7 = select i1 %6, i32 1, i32 -1
br label %8
8: ; preds = %4, %12
%9 = phi i32 [ %0, %4 ], [ %14, %12 ]
%10 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @__yield_setjmp to i32 (i8*, i8*, ...)*)(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.range, i64 0, i64 0))
%11 = icmp eq i32 %10, 42
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i32 (...) @__yield_postjump()
%14 = add nsw i32 %9, %7
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %8
16: ; preds = %12, %8, %2
%17 = phi i32 [ 0, %2 ], [ %9, %8 ], [ 0, %12 ]
ret i32 %17
}