#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 */
typedef int time_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int pthread_self();
int /*<<< orphan*/ sleep(int);
int time(int /*<<< orphan*/);
void *util() {
  int ten = 10;
  time_t start, end;
  while (ten--) {
    printf("Self id %d\n n=%d", pthread_self(), ten);
    start = time(0);
    end = start;
    while (((end - start) < 5))
      end = time(0);
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<util>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xa,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11b8 <util+0x78>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x5,%eax
jge    11a9 <util+0x69>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
jmp    118b <util+0x4b>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    114f <util+0xf>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util>:
push   %rbp
push   %r14
push   %rbx
mov    $0x9,%ebx
lea    0xeb0(%rip),%r14
xor    %eax,%eax
call   1050 <pthread_self@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
nopl   0x0(%rax)
xor    %edi,%edi
call   1040 <time@plt>
sub    %ebp,%eax
cmp    $0x5,%eax
jl     1170 <util+0x30>
mov    $0x5,%edi
call   1060 <sleep@plt>
sub    $0x1,%ebx
jae    1150 <util+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Self id %d\0A n=%d\00"
define noalias i8* @util() {
br label %1
1: ; preds = %0, %10
%2 = phi i32 [ 9, %0 ], [ %12, %10 ]
%3 = tail call i32 (...) @pthread_self()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %2)
%5 = tail call i32 @time(i32 0)
br label %6
6: ; preds = %1, %6
%7 = tail call i32 @time(i32 0)
%8 = sub nsw i32 %7, %5
%9 = icmp slt i32 %8, 5
br i1 %9, label %6, label %10
10: ; preds = %6
%11 = tail call i32 @sleep(i32 5)
%12 = add nsw i32 %2, -1
%13 = icmp eq i32 %2, 0
br i1 %13, label %14, label %1
14: ; preds = %10
ret i8* undef
}