#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ ucontext_t;

/* Variables and functions */
int /*<<< orphan*/ swapcontext(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
void loop(ucontext_t *loop_context, ucontext_t *other_context,
          int *i_from_iterator) {
  int i;
  for (i = 0; i < 10; ++i) {
    *i_from_iterator = i;
    swapcontext(loop_context, other_context);
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1159 <loop+0x49>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <swapcontext@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <loop+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rdx)
call   1030 <swapcontext@plt>
movl   $0x1,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x2,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x3,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x4,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x5,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x6,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x7,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x8,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swapcontext@plt>
movl   $0x9,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <swapcontext@plt>

LLVM IR (-O0):
define void @loop(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %17, %3
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %7
%13 = load i32*, i32** %6
store i32 %12, i32* %13
%14 = load i32*, i32** %4
%15 = load i32*, i32** %5
%16 = call i32 @swapcontext(i32* %14, i32* %15)
br label %17
17: ; preds = %11
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %8
20: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @loop(i32* %0, i32* %1, i32* nocapture writeonly %2) {
store i32 0, i32* %2
%4 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 1, i32* %2
%5 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 2, i32* %2
%6 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 3, i32* %2
%7 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 4, i32* %2
%8 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 5, i32* %2
%9 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 6, i32* %2
%10 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 7, i32* %2
%11 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 8, i32* %2
%12 = tail call i32 @swapcontext(i32* %0, i32* %1)
store i32 9, i32* %2
%13 = tail call i32 @swapcontext(i32* %0, i32* %1)
ret void
}