#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 */
unsigned int getnexttime();
int /*<<< orphan*/ old_usleep(int);
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned int realsleep(unsigned int);
scalar_t__ sleepy();
void *__m_thread_routine(void *arg) {
  unsigned int nexttime;
  unsigned int delta;
  while (1) {
    if (sleepy()) {
      printf("sleepy-pre(%u)\n", nexttime);
      nexttime = getnexttime();
      printf("sleepy-post(%u)\n", nexttime);
      delta = realsleep(nexttime);
    }
    old_usleep(10);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<__m_thread_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <sleepy@plt>
cmp    $0x0,%rax
je     11a0 <__m_thread_routine+0x50>
mov    -0xc(%rbp),%esi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getnexttime@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <realsleep@plt>
mov    %eax,-0x10(%rbp)
mov    $0xa,%edi
call   1060 <old_usleep@plt>
jmp    115c <__m_thread_routine+0xc>

x86 assembly (clang, -O2):
<__m_thread_routine>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%r14
lea    0xeae(%rip),%rbx
jmp    117a <__m_thread_routine+0x2a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xa,%edi
call   1060 <old_usleep@plt>
xor    %eax,%eax
call   1030 <sleepy@plt>
test   %rax,%rax
je     1170 <__m_thread_routine+0x20>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getnexttime@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <realsleep@plt>
jmp    1170 <__m_thread_routine+0x20>

LLVM IR (-O0):
@.str = [16 x i8] c"sleepy-pre(%u)\0A\00"
@.str.1 = [17 x i8] c"sleepy-post(%u)\0A\00"
define i8* @__m_thread_routine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %1, %16
%6 = call i64 (...) @sleepy()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i32, i32* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (...) @getnexttime()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
%15 = call i32 @realsleep(i32 %14)
store i32 %15, i32* %4
br label %16
16: ; preds = %8, %5
%17 = call i32 @old_usleep(i32 10)
br label %5
}

LLVM IR (-O2):
@.str = [16 x i8] c"sleepy-pre(%u)\0A\00"
@.str.1 = [17 x i8] c"sleepy-post(%u)\0A\00"
define noalias i8* @__m_thread_routine(i8* nocapture readnone %0) {
br label %2
2: ; preds = %11, %1
%3 = phi i32 [ undef, %1 ], [ %12, %11 ]
%4 = tail call i64 (...) @sleepy()
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
%8 = tail call i32 (...) @getnexttime()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @realsleep(i32 %8)
br label %11
11: ; preds = %6, %2
%12 = phi i32 [ %8, %6 ], [ %3, %2 ]
%13 = tail call i32 @old_usleep(i32 10)
br label %2
}