#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, int);
int /*<<< orphan*/ pthread_yield();
int rand();
void *somefunction(int *arg) {
  int loops = rand();
  for (int i = 0; i < loops; i++) {
    pthread_yield();
    for (; i < loops; i++)
      ;
  }
  printf("%d:\t%d\n", *arg, loops);
  return NULL;
}


x86 assembly (clang, -O0):
<somefunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <somefunction+0x62>
mov    $0x0,%al
call   1040 <pthread_yield@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117f <somefunction+0x4f>
jmp    1171 <somefunction+0x41>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <somefunction+0x30>
jmp    1184 <somefunction+0x54>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <somefunction+0x1d>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<somefunction>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1163 <somefunction+0x33>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <pthread_yield@plt>
cmp    %ebx,%ebp
cmovg  %ebp,%ebx
add    $0x1,%ebx
cmp    %ebp,%ebx
jl     1150 <somefunction+0x20>
mov    (%r14),%esi
lea    0xe93(%rip),%rdi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%d:\09%d\0A\00"
define i8* @somefunction(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32 (...) @rand()
store i32 %5, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = call i32 (...) @pthread_yield()
br label %12
12: ; preds = %17, %10
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %12
br label %17
17: ; preds = %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %12
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %6
24: ; preds = %6
%25 = load i32*, i32** %2
%26 = load i32, i32* %25
%27 = load i32, i32* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
ret i8* null
}

LLVM IR (-O2):
@.str = [8 x i8] c"%d:\09%d\0A\00"
define noalias i8* @somefunction(i32* nocapture %0) {
%2 = tail call i32 (...) @rand()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %7, %1
%5 = load i32, i32* %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %2)
ret i8* null
7: ; preds = %1, %7
%8 = phi i32 [ %11, %7 ], [ 0, %1 ]
%9 = tail call i32 (...) @pthread_yield()
%10 = call i32 @llvm.smax.i32(i32 %2, i32 %8)
%11 = add nsw i32 %10, 1
%12 = icmp slt i32 %11, %2
br i1 %12, label %7, label %4
}