#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 */
struct ringbuffer {
  int dummy;
};
typedef int /*<<< orphan*/ i;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ringbuffer_is_full(struct ringbuffer *);
int ringbuffer_len(struct ringbuffer *);
int /*<<< orphan*/ ringbuffer_put(struct ringbuffer *, char *, int);
int /*<<< orphan*/ sleep(int);
void *producer_proc(void *arg) {
  struct ringbuffer *ring_buf = (struct ringbuffer *)arg;
  char i;
  i = 0;
  while (1) {
    printf("******************************************\n");
    printf("put datas to ring buffer.\n");
    if (ringbuffer_is_full(ring_buf)) {
      printf("buffer is full !\n");
      sleep(1);
      continue;
    }
    ringbuffer_put(ring_buf, &i, sizeof(i));
    i++;
    printf("ring buffer length: %u\n", ringbuffer_len(ring_buf));
    printf("******************************************\n");
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<producer_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ringbuffer_is_full@plt>
cmp    $0x0,%rax
je     11b4 <producer_proc+0x64>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1168 <producer_proc+0x18>
mov    -0x10(%rbp),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <ringbuffer_put@plt>
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ringbuffer_len@plt>
mov    %eax,%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1168 <producer_proc+0x18>

x86 assembly (clang, -O2):
<producer_proc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,0x7(%rsp)
lea    0xeb8(%rip),%r14
lea    0xe97(%rip),%r15
lea    0xed5(%rip),%rbp
lea    0x7(%rsp),%r12
lea    0xe6c(%rip),%r13
jmp    11af <producer_proc+0x4f>
cs nopw 0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <ringbuffer_is_full@plt>
mov    %rbp,%rdi
test   %rax,%rax
jne    11a0 <producer_proc+0x40>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <ringbuffer_put@plt>
addb   $0x1,0x7(%rsp)
mov    %rbx,%rdi
call   1060 <ringbuffer_len@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
jmp    11a0 <producer_proc+0x40>

LLVM IR (-O0):
%struct.ringbuffer = type { i32 }
@.str = [44 x i8] c"******************************************\0A\00"
@.str.1 = [27 x i8] c"put datas to ring buffer.\0A\00"
@.str.2 = [18 x i8] c"buffer is full !\0A\00"
@.str.3 = [24 x i8] c"ring buffer length: %u\0A\00"
define i8* @producer_proc(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ringbuffer*
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to %struct.ringbuffer*
store %struct.ringbuffer* %6, %struct.ringbuffer** %3
store i8 0, i8* %4
br label %7
7: ; preds = %1, %13, %16
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%10 = load %struct.ringbuffer*, %struct.ringbuffer** %3
%11 = call i64 @ringbuffer_is_full(%struct.ringbuffer* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @sleep(i32 1)
br label %7
16: ; preds = %7
%17 = load %struct.ringbuffer*, %struct.ringbuffer** %3
%18 = call i32 @ringbuffer_put(%struct.ringbuffer* %17, i8* %4, i32 1)
%19 = load i8, i8* %4
%20 = add i8 %19, 1
store i8 %20, i8* %4
%21 = load %struct.ringbuffer*, %struct.ringbuffer** %3
%22 = call i32 @ringbuffer_len(%struct.ringbuffer* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @sleep(i32 1)
br label %7
}

LLVM IR (-O2):
%struct.ringbuffer = type { i32 }
@.str.3 = [24 x i8] c"ring buffer length: %u\0A\00"
@str.4 = [26 x i8] c"put datas to ring buffer.\00"
@str.5 = [43 x i8] c"******************************************\00"
@str.6 = [17 x i8] c"buffer is full !\00"
define noalias i8* @producer_proc(i8* %0) {
%2 = alloca i8
%3 = bitcast i8* %0 to %struct.ringbuffer*
store i8 0, i8* %2
br label %4
4: ; preds = %9, %1
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.5, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
%7 = call i64 @ringbuffer_is_full(%struct.ringbuffer* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4, %13
%10 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.5, i64 0, i64 0), %13 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0), %4 ]
%11 = call i32 @puts(i8* dereferenceable(1) %10)
%12 = call i32 @sleep(i32 1)
br label %4
13: ; preds = %4
%14 = call i32 @ringbuffer_put(%struct.ringbuffer* %3, i8* %2, i32 1)
%15 = load i8, i8* %2
%16 = add i8 %15, 1
store i8 %16, i8* %2
%17 = call i32 @ringbuffer_len(%struct.ringbuffer* %3)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %9
}