#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 */
struct tms {
  int dummy;
};
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, char const *);
int sched_yield();
scalar_t__ times(struct tms *);
int wall_time(struct tms *);
void run_loop(const char *label) {
  int curr_quarter, total_quarters;
  struct tms tdata;
  curr_quarter = 0;
  total_quarters = 12;
  for (;;) {
    if (times(&tdata) == (clock_t)-1)
      pexit("times");
    if (wall_time(&tdata) >= (curr_quarter + 1) * 0.25) {
      printf("[%s] 1/4 of second.\n", label);
      ++curr_quarter;
      if (curr_quarter % 4 == 0) {
        printf("[%s] Yielding\n", label);
        if (sched_yield() == -1)
          pexit("sched_yield");
      }
      if (curr_quarter == total_quarters) {
        printf("[%s] Finished\n", label);
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<run_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xc,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <times@plt>
cmp    $0xffffffffffffffff,%rax
jne    1189 <run_loop+0x39>
lea    0xe84(%rip),%rdi
call   1070 <pexit@plt>
lea    -0x18(%rbp),%rdi
call   1060 <wall_time@plt>
cvtsi2sd %eax,%xmm0
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe58(%rip),%xmm2
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     123a <run_loop+0xea>
mov    -0x8(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1214 <run_loop+0xc4>
mov    -0x8(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <sched_yield@plt>
cmp    $0xffffffff,%eax
jne    120f <run_loop+0xbf>
lea    0xe28(%rip),%rdi
call   1070 <pexit@plt>
jmp    1214 <run_loop+0xc4>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1235 <run_loop+0xe5>
mov    -0x8(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
jmp    123f <run_loop+0xef>
jmp    123a <run_loop+0xea>
jmp    116a <run_loop+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
lea    0xe9b(%rip),%r15
lea    0xe9a(%rip),%r12
lea    0xea8(%rip),%r13
xor    %ebp,%ebp
jmp    1196 <run_loop+0x46>
nop
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
test   $0x3,%bpl
je     11e0 <run_loop+0x90>
cmp    $0xc,%ebp
je     1205 <run_loop+0xb5>
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe58(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    11c7 <run_loop+0x77>
mov    %rbx,%rdi
call   1060 <wall_time@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0x8(%rsp),%xmm0
jae    1180 <run_loop+0x30>
mov    %rbx,%rdi
call   1050 <times@plt>
cmp    $0xffffffffffffffff,%rax
jne    11b0 <run_loop+0x60>
mov    %r15,%rdi
call   1070 <pexit@plt>
jmp    11b0 <run_loop+0x60>
nop
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <sched_yield@plt>
cmp    $0xffffffff,%eax
jne    1191 <run_loop+0x41>
lea    0xe34(%rip),%rdi
call   1070 <pexit@plt>
jmp    1191 <run_loop+0x41>
lea    0xe32(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [6 x i8] c"times\00"
@.str.1 = [21 x i8] c"[%s] 1/4 of second.\0A\00"
@.str.2 = [15 x i8] c"[%s] Yielding\0A\00"
@.str.3 = [12 x i8] c"sched_yield\00"
@.str.4 = [15 x i8] c"[%s] Finished\0A\00"
define void @run_loop(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.tms
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 12, i32* %4
br label %6
6: ; preds = %43, %1
%7 = call i64 @times(%struct.tms* %5)
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = call i32 @wall_time(%struct.tms* %5)
%13 = sitofp i32 %12 to double
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 2.500000e-01
%18 = fcmp oge double %13, %17
br i1 %18, label %19, label %43
19: ; preds = %11
%20 = load i8*, i8** %2
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = srem i32 %24, 4
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %19
%28 = load i8*, i8** %2
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 (...) @sched_yield()
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %35
35: ; preds = %34, %19
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i8*, i8** %2
%41 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %44
42: ; preds = %35
br label %43
43: ; preds = %42, %11
br label %6
44: ; preds = %39
ret void
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str = [6 x i8] c"times\00"
@.str.1 = [21 x i8] c"[%s] 1/4 of second.\0A\00"
@.str.2 = [15 x i8] c"[%s] Yielding\0A\00"
@.str.3 = [12 x i8] c"sched_yield\00"
@.str.4 = [15 x i8] c"[%s] Finished\0A\00"
define void @run_loop(i8* %0) {
%2 = alloca %struct.tms
%3 = bitcast %struct.tms* %2 to i8*
br label %4
4: ; preds = %28, %1
%5 = phi i32 [ %6, %28 ], [ 0, %1 ]
%6 = add nuw nsw i32 %5, 1
%7 = sitofp i32 %6 to double
%8 = fmul double %7, 2.500000e-01
br label %9
9: ; preds = %4, %14
%10 = call i64 @times(%struct.tms* %2)
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = call i32 @wall_time(%struct.tms* %2)
%16 = sitofp i32 %15 to double
%17 = fcmp ugt double %8, %16
br i1 %17, label %9, label %18
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = and i32 %6, 3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%24 = call i32 (...) @sched_yield()
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %22, %26, %18
%29 = icmp eq i32 %6, 12
br i1 %29, label %30, label %4
30: ; preds = %28
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %0)
ret void
}