#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*/ usleep(int);
int /*<<< orphan*/ yield();
void func4(void) {
  int j = 0;
  printf("func4B: started\n");
  while (1) {
    printf("[%d] ", ++j);
    printf("func4B: swapcontext\n");
    yield();
    printf("func4B: returning\n");
    usleep(500000);
  }
}


x86 assembly (clang, -O0):
<func4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%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    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <yield@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1050 <usleep@plt>
jmp    114d <func4+0x1d>

x86 assembly (clang, -O2):
<func4>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
lea    0xea0(%rip),%r14
lea    0xeaf(%rip),%r15
lea    0xebc(%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>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
add    $0x1,%ebx
jmp    1170 <func4+0x30>

LLVM IR (-O0):
@.str = [17 x i8] c"func4B: started\0A\00"
@.str.1 = [6 x i8] c"[%d] \00"
@.str.2 = [21 x i8] c"func4B: swapcontext\0A\00"
@.str.3 = [19 x i8] c"func4B: returning\0A\00"
define void @func4() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 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 ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (...) @yield()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @usleep(i32 500000)
br label %3
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"[%d] \00"
@str = [16 x i8] c"func4B: started\00"
@str.4 = [20 x i8] c"func4B: swapcontext\00"
@str.5 = [18 x i8] c"func4B: returning\00"
define void @func4() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = phi i32 [ 0, %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 ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%7 = tail call i32 (...) @yield()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%9 = tail call i32 @usleep(i32 500000)
br label %2
}