#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*/ alarm(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *, int, char *);
int sched_yield();
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int child_busy(int fd) {
  int rc;
  alarm(4);
  write(fd, "go", 2);
  for (;;) {
    rc = sched_yield();
    if (rc) {
      printf("Failed: %s rc: %d errno: %s\n", "child: sched_yield", rc,
             strerror(errno));
      exit(1);
    }
  }
  exit(2);
}


x86 assembly (clang, -O0):
<child_busy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <alarm@plt>
mov    -0x4(%rbp),%edi
lea    0xe81(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1060 <sched_yield@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d4 <child_busy+0x74>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0xc(%rbp),%edx
mov    %rax,%rcx
lea    0xe45(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1189 <child_busy+0x29>

x86 assembly (clang, -O2):
<child_busy>:
push   %rbx
mov    %edi,%ebx
mov    $0x4,%edi
call   1050 <alarm@plt>
lea    0xe8c(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1060 <sched_yield@plt>
test   %eax,%eax
je     1180 <child_busy+0x20>
mov    %eax,%ebx
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe61(%rip),%rdi
lea    0xe77(%rip),%rsi
mov    %ebx,%edx
mov    %rax,%rcx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"go\00"
@.str.1 = [29 x i8] c"Failed: %s rc: %d errno: %s\0A\00"
@.str.2 = [19 x i8] c"child: sched_yield\00"
@errno = global i32 0
define i32 @child_busy(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @alarm(i32 4)
%5 = load i32, i32* %2
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %7
7: ; preds = %17, %1
%8 = call i32 (...) @sched_yield()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %7
br label %7
}

LLVM IR (-O2):
@.str = [3 x i8] c"go\00"
@.str.1 = [29 x i8] c"Failed: %s rc: %d errno: %s\0A\00"
@.str.2 = [19 x i8] c"child: sched_yield\00"
@errno = global i32 0
define i32 @child_busy(i32 %0) {
%2 = tail call i32 @alarm(i32 4)
%3 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %4
4: ; preds = %4, %1
%5 = tail call i32 (...) @sched_yield()
%6 = icmp eq i32 %5, 0
br i1 %6, label %4, label %7
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %5, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
}