#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*/ sleep(int);
int /*<<< orphan*/ write_to_pingpong_buf(struct pingpong_buffer *, int);
void *pingpong_write(void *arg) {
  uint32_t ret;
  struct pingpong_buffer *pp_buf;
  pp_buf = (struct pingpong_buffer *)arg;
  while (1) {
    printf("\n******************** write ************************\n");
    ret = write_to_pingpong_buf(pp_buf, 0x80);
    if (!ret) {
      printf("write wait ......\n");
      sleep(1);
    }
  }
}


x86 assembly (clang, -O0):
<pingpong_write>:
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   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x80,%esi
call   1040 <write_to_pingpong_buf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1181 <pingpong_write+0x51>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1144 <pingpong_write+0x14>

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

LLVM IR (-O0):
%struct.pingpong_buffer = type { i32 }
@.str = [54 x i8] c"\0A******************** write ************************\0A\00"
@.str.1 = [19 x i8] c"write wait ......\0A\00"
define i8* @pingpong_write(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 ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.pingpong_buffer*, %struct.pingpong_buffer** %4
%10 = call i32 @write_to_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 ([19 x i8], [19 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 = [53 x i8] c"\0A******************** write ************************\00"
@str.2 = [18 x i8] c"write wait ......\00"
define noalias i8* @pingpong_write(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 ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @write_to_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 ([18 x i8], [18 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
}