#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 read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ usleep(int);
void readFrame(int fd, char *tabRecu) {
  int bytesRead = 0;
  while (tabRecu[0] != 2) {
    usleep(2000);
    bytesRead = read(fd, tabRecu, 1);
  }
  if (tabRecu[0] == 2) {
    sleep(1);
    usleep(400000);
    bytesRead = read(fd, &tabRecu[1], 179);
    tabRecu[bytesRead + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<readFrame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2,%eax
je     1179 <readFrame+0x49>
mov    $0x7d0,%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
jmp    1146 <readFrame+0x16>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2,%eax
jne    11c6 <readFrame+0x96>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    $0x61a80,%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0xb3,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFrame>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmpb   $0x2,(%rsi)
je     115e <readFrame+0x2e>
nopl   (%rax)
mov    $0x7d0,%edi
call   1050 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmpb   $0x2,(%rbx)
jne    1140 <readFrame+0x10>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    $0x61a80,%edi
call   1050 <usleep@plt>
lea    0x1(%rbx),%rsi
mov    %ebp,%edi
mov    $0xb3,%edx
call   1030 <read@plt>
cltq
movb   $0x0,0x1(%rax,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @readFrame(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %12, %2
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = call i32 @usleep(i32 2000)
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = call i32 @read(i32 %14, i8* %15, i32 1)
store i32 %16, i32* %5
br label %6
17: ; preds = %6
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = call i32 @sleep(i32 1)
%25 = call i32 @usleep(i32 400000)
%26 = load i32, i32* %3
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @read(i32 %26, i8* %28, i32 179)
store i32 %29, i32* %5
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %23, %17
ret void
}

LLVM IR (-O2):
define void @readFrame(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 2
br i1 %4, label %10, label %5
5: ; preds = %2, %5
%6 = tail call i32 @usleep(i32 2000)
%7 = tail call i32 @read(i32 %0, i8* %1, i32 1)
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 2
br i1 %9, label %10, label %5
10: ; preds = %5, %2
%11 = tail call i32 @sleep(i32 1)
%12 = tail call i32 @usleep(i32 400000)
%13 = getelementptr inbounds i8, i8* %1, i64 1
%14 = tail call i32 @read(i32 %0, i8* %13, i32 179)
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
ret void
}