#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 myRead(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ threadExit();
int /*<<< orphan*/ waitMs(int);
void *reader(void *param) {
  int i;
  int result;
  printf("--> reader !\n");
  for (i = 0; i < 4; i++) {
    result = myRead(0, 0);
    printf("%d result %d\n", i, result);
    waitMs(1500);
  }
  threadExit();
  return NULL;
}


x86 assembly (clang, -O0):
<reader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    11a3 <reader+0x63>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <myRead@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5dc,%edi
call   1060 <waitMs@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <reader+0x21>
mov    $0x0,%al
call   1040 <threadExit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reader>:
push   %rbx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <myRead@plt>
lea    0xe93(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5dc,%edi
call   1070 <waitMs@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <myRead@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5dc,%edi
call   1070 <waitMs@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <myRead@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5dc,%edi
call   1070 <waitMs@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <myRead@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5dc,%edi
call   1070 <waitMs@plt>
xor    %eax,%eax
call   1050 <threadExit@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"--> reader !\0A\00"
@.str.1 = [14 x i8] c"%d result %d\0A\00"
define i8* @reader(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %15, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i32 @myRead(i32 0, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 @waitMs(i32 1500)
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
%19 = call i32 (...) @threadExit()
ret i8* null
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"%d result %d\0A\00"
@str = [13 x i8] c"--> reader !\00"
define noalias i8* @reader(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @myRead(i32 0, i32 0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %3)
%5 = tail call i32 @waitMs(i32 1500)
%6 = tail call i32 @myRead(i32 0, i32 0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %6)
%8 = tail call i32 @waitMs(i32 1500)
%9 = tail call i32 @myRead(i32 0, i32 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %9)
%11 = tail call i32 @waitMs(i32 1500)
%12 = tail call i32 @myRead(i32 0, i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %12)
%14 = tail call i32 @waitMs(i32 1500)
%15 = tail call i32 (...) @threadExit()
ret i8* null
}