#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 sas_trylock_ptr(void volatile **);
int /*<<< orphan*/ sched_yield();
void sas_lock_ptr_with_yield(volatile void **lock) {
  int rc;
  if (sas_trylock_ptr(lock) == 0)
    return;
  if (sas_trylock_ptr(lock) == 0)
    return;
  if (sas_trylock_ptr(lock) == 0)
    return;
  if (sas_trylock_ptr(lock) == 0)
    return;
  do {
    sched_yield();
    rc = sas_trylock_ptr(lock);
  } while (rc);
  return;
}


x86 assembly (clang, -O0):
<sas_lock_ptr_with_yield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sas_trylock_ptr@plt>
cmp    $0x0,%eax
jne    1143 <sas_lock_ptr_with_yield+0x23>
jmp    11af <sas_lock_ptr_with_yield+0x8f>
mov    -0x8(%rbp),%rdi
call   1030 <sas_trylock_ptr@plt>
cmp    $0x0,%eax
jne    115a <sas_lock_ptr_with_yield+0x3a>
jmp    11af <sas_lock_ptr_with_yield+0x8f>
mov    -0x8(%rbp),%rdi
call   1030 <sas_trylock_ptr@plt>
cmp    $0x0,%eax
jne    1171 <sas_lock_ptr_with_yield+0x51>
jmp    11af <sas_lock_ptr_with_yield+0x8f>
mov    -0x8(%rbp),%rdi
call   1030 <sas_trylock_ptr@plt>
cmp    $0x0,%eax
jne    1188 <sas_lock_ptr_with_yield+0x68>
jmp    11af <sas_lock_ptr_with_yield+0x8f>
jmp    118d <sas_lock_ptr_with_yield+0x6d>
mov    $0x0,%al
call   1040 <sched_yield@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sas_trylock_ptr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    118d <sas_lock_ptr_with_yield+0x6d>
jmp    11af <sas_lock_ptr_with_yield+0x8f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sas_lock_ptr_with_yield>:
push   %rbx
mov    %rdi,%rbx
call   1030 <sas_trylock_ptr@plt>
test   %eax,%eax
je     1165 <sas_lock_ptr_with_yield+0x45>
mov    %rbx,%rdi
call   1030 <sas_trylock_ptr@plt>
test   %eax,%eax
je     1165 <sas_lock_ptr_with_yield+0x45>
mov    %rbx,%rdi
call   1030 <sas_trylock_ptr@plt>
test   %eax,%eax
je     1165 <sas_lock_ptr_with_yield+0x45>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <sas_trylock_ptr@plt>
test   %eax,%eax
je     1165 <sas_lock_ptr_with_yield+0x45>
xor    %eax,%eax
call   1040 <sched_yield@plt>
jmp    1150 <sas_lock_ptr_with_yield+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @sas_lock_ptr_with_yield(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = call i32 @sas_trylock_ptr(i8** %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %32
8: ; preds = %1
%9 = load i8**, i8*** %2
%10 = call i32 @sas_trylock_ptr(i8** %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %32
13: ; preds = %8
%14 = load i8**, i8*** %2
%15 = call i32 @sas_trylock_ptr(i8** %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %32
18: ; preds = %13
%19 = load i8**, i8*** %2
%20 = call i32 @sas_trylock_ptr(i8** %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %32
23: ; preds = %18
br label %24
24: ; preds = %28, %23
%25 = call i32 (...) @sched_yield()
%26 = load i8**, i8*** %2
%27 = call i32 @sas_trylock_ptr(i8** %26)
store i32 %27, i32* %3
br label %28
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
br i1 %30, label %24, label %31
31: ; preds = %28
br label %32
32: ; preds = %31, %22, %17, %12, %7
ret void
}

LLVM IR (-O2):
define void @sas_lock_ptr_with_yield(i8** %0) {
%2 = tail call i32 @sas_trylock_ptr(i8** %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32 @sas_trylock_ptr(i8** %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i32 @sas_trylock_ptr(i8** %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i32 @sas_trylock_ptr(i8** %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10, %13
%14 = tail call i32 (...) @sched_yield()
%15 = tail call i32 @sas_trylock_ptr(i8** %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %13
17: ; preds = %13, %10, %7, %4, %1
ret void
}