#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ yield();
void func4(void) {
  int j = 10;
  printf("func4: started\n");
  while (1) {
    printf("[%d] ", ++j);
    printf("func4: swapcontext(&uctx_func3, &uctx_func1)\n");
    yield();
    printf("func4: returning\n");
  }
}


x86 assembly (clang, -O0):
<func4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xa,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
mov    %esi,-0x4(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <yield@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    113d <func4+0x1d>

x86 assembly (clang, -O2):
<func4>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
mov    $0xb,%ebx
lea    0xeb0(%rip),%r14
lea    0xebe(%rip),%r15
lea    0xee4(%rip),%r12
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <yield@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
jmp    1160 <func4+0x30>

LLVM IR (-O0):
@.str = [16 x i8] c"func4: started\0A\00"
@.str.1 = [6 x i8] c"[%d] \00"
@.str.2 = [46 x i8] c"func4: swapcontext(&uctx_func3, &uctx_func1)\0A\00"
@.str.3 = [18 x i8] c"func4: returning\0A\00"
define void @func4() {
%1 = alloca i32
store i32 10, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %0, %3
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (...) @yield()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %3
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"[%d] \00"
@str = [15 x i8] c"func4: started\00"
@str.4 = [45 x i8] c"func4: swapcontext(&uctx_func3, &uctx_func1)\00"
@str.5 = [17 x i8] c"func4: returning\00"
define void @func4() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = phi i32 [ 10, %0 ], [ %4, %2 ]
%4 = add nuw nsw i32 %3, 1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.4, i64 0, i64 0))
%7 = tail call i32 (...) @yield()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %2
}