#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 /*<<< orphan*/ uint32_t;
struct pingpong_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_from_pingpong_buf(struct pingpong_buffer *, int);
int /*<<< orphan*/ sleep(int);
void *pingpong_read(void *arg) {
  uint32_t ret;
  struct pingpong_buffer *pp_buf;
  pp_buf = (struct pingpong_buffer *)arg;
  while (1) {
    printf("\n******************** read ************************\n");
    ret = read_from_pingpong_buf(pp_buf, 0x80);
    if (!ret) {
      printf("read wait ......\n");
      sleep(1);
    }
  }
}


x86 assembly (clang, -O0):
<pingpong_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x80,%esi
call   1030 <read_from_pingpong_buf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1181 <pingpong_read+0x51>
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1144 <pingpong_read+0x14>

x86 assembly (clang, -O2):
<pingpong_read>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xec1(%rip),%r14
lea    0xeee(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
call   1030 <read_from_pingpong_buf@plt>
test   %eax,%eax
jne    1150 <pingpong_read+0x20>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1150 <pingpong_read+0x20>

LLVM IR (-O0):
%struct.pingpong_buffer = type { i32 }
@.str = [53 x i8] c"\0A******************** read ************************\0A\00"
@.str.1 = [18 x i8] c"read wait ......\0A\00"
define i8* @pingpong_read(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.pingpong_buffer*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to %struct.pingpong_buffer*
store %struct.pingpong_buffer* %6, %struct.pingpong_buffer** %4
br label %7
7: ; preds = %1, %16
%8 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.pingpong_buffer*, %struct.pingpong_buffer** %4
%10 = call i32 @read_from_pingpong_buf(%struct.pingpong_buffer* %9, i32 128)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @sleep(i32 1)
br label %16
16: ; preds = %13, %7
br label %7
}

LLVM IR (-O2):
%struct.pingpong_buffer = type { i32 }
@str = [52 x i8] c"\0A******************** read ************************\00"
@str.2 = [17 x i8] c"read wait ......\00"
define noalias i8* @pingpong_read(i8* %0) {
%2 = bitcast i8* %0 to %struct.pingpong_buffer*
br label %3
3: ; preds = %10, %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @read_from_pingpong_buf(%struct.pingpong_buffer* %2, i32 128)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.2, i64 0, i64 0))
%9 = tail call i32 @sleep(i32 1)
br label %10
10: ; preds = %7, %3
br label %3
}