#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 *, char *);
int /*<<< orphan*/ taskSwitch(int);
void printMessageSleep(void *ptr) {
  char *message;
  unsigned i, j;
  message = (char *)ptr;
  for (i = 0; i < 5; i++) {
    printf("%s  \n", message);
    for (j = 0; j < 500000; j++) {
    }
  }
  taskSwitch(2000);
  for (i = 0; i < 10; i++) {
    if (!(i % 2))
      printf("%s -> tic\n", message);
    else
      printf("%s -> tac\n", message);
    taskSwitch(1000);
  }
  taskSwitch(-1);
}


x86 assembly (clang, -O0):
<printMessageSleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jae    118f <printMessageSleep+0x6f>
mov    -0x10(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x7a120,-0x18(%rbp)
jae    117c <printMessageSleep+0x5c>
jmp    116e <printMessageSleep+0x4e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115c <printMessageSleep+0x3c>
jmp    1181 <printMessageSleep+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <printMessageSleep+0x1b>
mov    $0x7d0,%edi
call   1040 <taskSwitch@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jae    11f6 <printMessageSleep+0xd6>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11ce <printMessageSleep+0xae>
mov    -0x10(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    11de <printMessageSleep+0xbe>
mov    -0x10(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a0 <printMessageSleep+0x80>
mov    $0xffffffff,%edi
call   1040 <taskSwitch@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMessageSleep>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xed1(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x7d0,%edi
call   1040 <taskSwitch@plt>
lea    0xe8f(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
lea    0xe7e(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x3e8,%edi
call   1040 <taskSwitch@plt>
mov    $0xffffffff,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <taskSwitch@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s \0A\00"
@.str.1 = [11 x i8] c"%s -> tic\0A\00"
@.str.2 = [11 x i8] c"%s -> tac\0A\00"
define void @printMessageSleep(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %4
%9 = icmp ult i32 %8, 5
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %5
br label %13
13: ; preds = %17, %10
%14 = load i32, i32* %5
%15 = icmp ult i32 %14, 500000
br i1 %15, label %16, label %20
16: ; preds = %13
br label %17
17: ; preds = %16
%18 = load i32, i32* %5
%19 = add i32 %18, 1
store i32 %19, i32* %5
br label %13
20: ; preds = %13
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = call i32 @taskSwitch(i32 2000)
store i32 0, i32* %4
br label %26
26: ; preds = %41, %24
%27 = load i32, i32* %4
%28 = icmp ult i32 %27, 10
br i1 %28, label %29, label %44
29: ; preds = %26
%30 = load i32, i32* %4
%31 = urem i32 %30, 2
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %39
36: ; preds = %29
%37 = load i8*, i8** %3
%38 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %33
%40 = call i32 @taskSwitch(i32 1000)
br label %41
41: ; preds = %39
%42 = load i32, i32* %4
%43 = add i32 %42, 1
store i32 %43, i32* %4
br label %26
44: ; preds = %26
%45 = call i32 @taskSwitch(i32 -1)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s \0A\00"
@.str.1 = [11 x i8] c"%s -> tic\0A\00"
@.str.2 = [11 x i8] c"%s -> tac\0A\00"
define void @printMessageSleep(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @taskSwitch(i32 2000)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @taskSwitch(i32 1000)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = tail call i32 @taskSwitch(i32 1000)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @taskSwitch(i32 1000)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i32 @taskSwitch(i32 1000)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = tail call i32 @taskSwitch(i32 1000)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%19 = tail call i32 @taskSwitch(i32 1000)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = tail call i32 @taskSwitch(i32 1000)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%23 = tail call i32 @taskSwitch(i32 1000)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%25 = tail call i32 @taskSwitch(i32 1000)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%27 = tail call i32 @taskSwitch(i32 1000)
%28 = tail call i32 @taskSwitch(i32 -1)
ret void
}