#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*/ pthread_yield();
int /*<<< orphan*/ write(int, char *, int);
void *bg_routine(void *arg) {
  write(1, "bg routine running\n", 19);
  while (1) {
    int n;
    char dot;
    dot = '.';
    pthread_yield();
    write(1, &dot, 1);
    pthread_yield();
    n = 1000;
    while (n-- > 0)
      pthread_yield();
  }
}


x86 assembly (clang, -O0):
<bg_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
lea    0xec8(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
movb   $0x2e,-0xd(%rbp)
mov    $0x0,%al
call   1040 <pthread_yield@plt>
mov    $0x1,%edx
lea    -0xd(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    $0x0,%al
call   1040 <pthread_yield@plt>
movl   $0x3e8,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    118b <bg_routine+0x6b>
mov    $0x0,%al
call   1040 <pthread_yield@plt>
jmp    116b <bg_routine+0x4b>
jmp    1142 <bg_routine+0x22>

x86 assembly (clang, -O2):
<bg_routine>:
push   %rbp
push   %rbx
push   %rax
lea    0xed6(%rip),%rsi
mov    $0x1,%edi
mov    $0x13,%edx
call   1030 <write@plt>
lea    0x7(%rsp),%rbx
xchg   %ax,%ax
movb   $0x2e,0x7(%rsp)
xor    %eax,%eax
call   1040 <pthread_yield@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1040 <pthread_yield@plt>
mov    $0x3e9,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <pthread_yield@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1170 <bg_routine+0x50>
jmp    1140 <bg_routine+0x20>

LLVM IR (-O0):
@.str = [20 x i8] c"bg routine running\0A\00"
define i8* @bg_routine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
%5 = call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
br label %6
6: ; preds = %1, %16
store i8 46, i8* %4
%7 = call i32 (...) @pthread_yield()
%8 = call i32 @write(i32 1, i8* %4, i32 1)
%9 = call i32 (...) @pthread_yield()
store i32 1000, i32* %3
br label %10
10: ; preds = %14, %6
%11 = load i32, i32* %3
%12 = add nsw i32 %11, -1
store i32 %12, i32* %3
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (...) @pthread_yield()
br label %10
16: ; preds = %10
br label %6
}

LLVM IR (-O2):
@.str = [20 x i8] c"bg routine running\0A\00"
define noalias i8* @bg_routine(i8* nocapture readnone %0) {
%2 = alloca i8
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
br label %4
4: ; preds = %1, %13
store i8 46, i8* %2
%5 = tail call i32 (...) @pthread_yield()
%6 = call i32 @write(i32 1, i8* %2, i32 1)
%7 = tail call i32 (...) @pthread_yield()
br label %8
8: ; preds = %4, %8
%9 = phi i32 [ 1000, %4 ], [ %10, %8 ]
%10 = add nsw i32 %9, -1
%11 = tail call i32 (...) @pthread_yield()
%12 = icmp ugt i32 %9, 1
br i1 %12, label %8, label %13
13: ; preds = %8
br label %4
}