#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*/ getcontext(int /*<<< orphan*/ *);
int /*<<< orphan*/ setcontext(int /*<<< orphan*/ *);
void time_getcontext(int count) {
  int i;
  volatile int ret;
  ucontext_t uc;
  for (i = 0; i < count; i++) {
    ret = 0;
    getcontext(&uc);
    if (ret == 1)
      continue;
    ret = 1;
    setcontext(&uc);
  }
}


x86 assembly (clang, -O0):
<time_getcontext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117d <time_getcontext+0x5d>
movl   $0x0,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <getcontext@plt>
mov    -0xc(%rbp),%eax
cmp    $0x1,%eax
jne    115f <time_getcontext+0x3f>
jmp    116f <time_getcontext+0x4f>
movl   $0x1,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <setcontext@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <time_getcontext+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_getcontext>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    115d <time_getcontext+0x3d>
lea    0x4(%rsp),%rbx
mov    %edi,%ebp
jmp    1135 <time_getcontext+0x15>
add    $0xffffffff,%ebp
je     115d <time_getcontext+0x3d>
movl   $0x0,(%rsp)
mov    %rbx,%rdi
call   1040 <getcontext@plt>
mov    (%rsp),%eax
cmp    $0x1,%eax
je     1130 <time_getcontext+0x10>
movl   $0x1,(%rsp)
mov    %rbx,%rdi
call   1030 <setcontext@plt>
jmp    1130 <time_getcontext+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @time_getcontext(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %17
7: ; preds = %1, %14
%8 = phi i32 [ %15, %14 ], [ 0, %1 ]
store volatile i32 0, i32* %2
%9 = call i32 @getcontext(i32* %3)
%10 = load volatile i32, i32* %2
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %7
store volatile i32 1, i32* %2
%13 = call i32 @setcontext(i32* %3)
br label %14
14: ; preds = %7, %12
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, %0
br i1 %16, label %17, label %7
17: ; preds = %14, %1
ret void
}