#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 circular_buffer {
  int dummy;
};

/* Variables and functions */
int circular_buffer_capacity(struct circular_buffer *);
int /*<<< orphan*/ circular_buffer_clear(struct circular_buffer *);
struct circular_buffer *circular_buffer_init(int);
int /*<<< orphan*/ circular_buffer_pop(struct circular_buffer *, char *,
                                       size_t *);
int /*<<< orphan*/ circular_buffer_push(struct circular_buffer *, char *, int);
int circular_buffer_size(struct circular_buffer *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char tmpBuf[1024];
  char helloBuf[] = "hello world";
  size_t nread;
  size_t i;
  struct circular_buffer *buf = circular_buffer_init(1024);
  printf("capacity: %d\n", circular_buffer_capacity(buf));
  printf("size: %d\n", circular_buffer_size(buf));
  printf("\n");
  circular_buffer_push(buf, helloBuf, 11);
  printf("size: %d\n", circular_buffer_size(buf));
  circular_buffer_push(buf, tmpBuf, 1024);
  printf("size: %d\n", circular_buffer_size(buf));
  printf("\n");
  circular_buffer_clear(buf);
  printf("size: %d\n", circular_buffer_size(buf));
  printf("\n");
  for (i = 0; i < 10; i++) {
    circular_buffer_push(buf, helloBuf, 11);
    circular_buffer_push(buf, helloBuf, 5);
  }
  for (i = 0; i < 20; i++) {
    circular_buffer_pop(buf, tmpBuf, &nread);
    tmpBuf[nread] = '\0';
    printf("nread: %d string: %s\n", nread, tmpBuf);
  }
  printf("\n");
  circular_buffer_pop(buf, tmpBuf, &nread);
  printf("nread: %d string: %s\n", nread, tmpBuf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x41c(%rbp)
mov    0xe72(%rip),%eax
mov    %eax,-0x414(%rbp)
mov    $0x400,%edi
call   1070 <circular_buffer_init@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
call   1090 <circular_buffer_capacity@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x438(%rbp),%rdi
call   1030 <circular_buffer_size@plt>
mov    %eax,%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x438(%rbp),%rdi
lea    -0x41c(%rbp),%rsi
mov    $0xb,%edx
call   1040 <circular_buffer_push@plt>
mov    -0x438(%rbp),%rdi
call   1030 <circular_buffer_size@plt>
mov    %eax,%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x438(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <circular_buffer_push@plt>
mov    -0x438(%rbp),%rdi
call   1030 <circular_buffer_size@plt>
mov    %eax,%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x438(%rbp),%rdi
call   1080 <circular_buffer_clear@plt>
mov    -0x438(%rbp),%rdi
call   1030 <circular_buffer_size@plt>
mov    %eax,%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x430(%rbp)
cmpq   $0xa,-0x430(%rbp)
0a
jae    12ff <main+0x18f>
mov    -0x438(%rbp),%rdi
lea    -0x41c(%rbp),%rsi
mov    $0xb,%edx
call   1040 <circular_buffer_push@plt>
mov    -0x438(%rbp),%rdi
lea    -0x41c(%rbp),%rsi
mov    $0x5,%edx
call   1040 <circular_buffer_push@plt>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    12aa <main+0x13a>
movq   $0x0,-0x430(%rbp)
cmpq   $0x14,-0x430(%rbp)
14
jae    1374 <main+0x204>
mov    -0x438(%rbp),%rdi
lea    -0x410(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1060 <circular_buffer_pop@plt>
mov    -0x428(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x428(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    130a <main+0x19a>
lea    0xca7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x438(%rbp),%rdi
lea    -0x410(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1060 <circular_buffer_pop@plt>
mov    -0x428(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xc73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x420,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,0x10(%rsp)
movl   $0x646c72,0x18(%rsp)
mov    $0x400,%edi
call   1080 <circular_buffer_init@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   10a0 <circular_buffer_capacity@plt>
lea    0xe49(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1030 <circular_buffer_size@plt>
lea    0xe3f(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x10(%rsp),%r15
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
call   1030 <circular_buffer_size@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%r14
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
call   1030 <circular_buffer_size@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r13,%rdi
call   1090 <circular_buffer_clear@plt>
mov    %r13,%rdi
call   1030 <circular_buffer_size@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1050 <circular_buffer_push@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <circular_buffer_push@plt>
mov    $0x14,%ebx
lea    0x8(%rsp),%r15
lea    0xc60(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <circular_buffer_pop@plt>
mov    0x8(%rsp),%rsi
movb   $0x0,0x20(%rsp,%rsi,1)
mov    %r12,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffffffffffff,%rbx
jne    13d0 <main+0x250>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <circular_buffer_pop@plt>
mov    0x8(%rsp),%rsi
lea    0xbfe(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.circular_buffer = type { i32 }
@__const.main.helloBuf = [12 x i8] c"hello world\00"
@.str = [14 x i8] c"capacity: %d\0A\00"
@.str.1 = [10 x i8] c"size: %d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [22 x i8] c"nread: %d string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [12 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.circular_buffer*
store i32 0, i32* %1
%7 = bitcast [12 x i8]* %3 to i8*
%8 = call %struct.circular_buffer* @circular_buffer_init(i32 1024)
store %struct.circular_buffer* %8, %struct.circular_buffer** %6
%9 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%10 = call i32 @circular_buffer_capacity(%struct.circular_buffer* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%13 = call i32 @circular_buffer_size(%struct.circular_buffer* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%18 = call i32 @circular_buffer_push(%struct.circular_buffer* %16, i8* %17, i32 11)
%19 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%20 = call i32 @circular_buffer_size(%struct.circular_buffer* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%24 = call i32 @circular_buffer_push(%struct.circular_buffer* %22, i8* %23, i32 1024)
%25 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%26 = call i32 @circular_buffer_size(%struct.circular_buffer* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%30 = call i32 @circular_buffer_clear(%struct.circular_buffer* %29)
%31 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%32 = call i32 @circular_buffer_size(%struct.circular_buffer* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %5
br label %35
35: ; preds = %45, %0
%36 = load i64, i64* %5
%37 = icmp ult i64 %36, 10
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%40 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%41 = call i32 @circular_buffer_push(%struct.circular_buffer* %39, i8* %40, i32 11)
%42 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%43 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%44 = call i32 @circular_buffer_push(%struct.circular_buffer* %42, i8* %43, i32 5)
br label %45
45: ; preds = %38
%46 = load i64, i64* %5
%47 = add i64 %46, 1
store i64 %47, i64* %5
br label %35
48: ; preds = %35
store i64 0, i64* %5
br label %49
49: ; preds = %61, %48
%50 = load i64, i64* %5
%51 = icmp ult i64 %50, 20
br i1 %51, label %52, label %64
52: ; preds = %49
%53 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%55 = call i32 @circular_buffer_pop(%struct.circular_buffer* %53, i8* %54, i64* %4)
%56 = load i64, i64* %4
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %56
store i8 0, i8* %57
%58 = load i64, i64* %4
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %58, i8* %59)
br label %61
61: ; preds = %52
%62 = load i64, i64* %5
%63 = add i64 %62, 1
store i64 %63, i64* %5
br label %49
64: ; preds = %49
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%66 = load %struct.circular_buffer*, %struct.circular_buffer** %6
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%68 = call i32 @circular_buffer_pop(%struct.circular_buffer* %66, i8* %67, i64* %4)
%69 = load i64, i64* %4
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %69, i8* %70)
ret i32 0
}

LLVM IR (-O2):
%struct.circular_buffer = type { i32 }
@__const.main.helloBuf = [12 x i8] c"hello world\00"
@.str = [14 x i8] c"capacity: %d\0A\00"
@.str.1 = [10 x i8] c"size: %d\0A\00"
@.str.3 = [22 x i8] c"nread: %d string: %s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [12 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%6 = bitcast i64* %3 to i8*
%7 = tail call %struct.circular_buffer* @circular_buffer_init(i32 1024)
%8 = tail call i32 @circular_buffer_capacity(%struct.circular_buffer* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @circular_buffer_size(%struct.circular_buffer* %7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @putchar(i32 10)
%13 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%14 = call i32 @circular_buffer_size(%struct.circular_buffer* %7)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %4, i32 1024)
%17 = call i32 @circular_buffer_size(%struct.circular_buffer* %7)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 @putchar(i32 10)
%20 = call i32 @circular_buffer_clear(%struct.circular_buffer* %7)
%21 = call i32 @circular_buffer_size(%struct.circular_buffer* %7)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 @putchar(i32 10)
%24 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%25 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%26 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%27 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%28 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%29 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%30 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%31 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%32 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%33 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%34 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%35 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%36 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%37 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%38 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%39 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%40 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%41 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
%42 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 11)
%43 = call i32 @circular_buffer_push(%struct.circular_buffer* %7, i8* %5, i32 5)
br label %44
44: ; preds = %0, %44
%45 = phi i64 [ %50, %44 ], [ 0, %0 ]
%46 = call i32 @circular_buffer_pop(%struct.circular_buffer* %7, i8* %4, i64* %3)
%47 = load i64, i64* %3
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %47, i8* %4)
%50 = add nuw nsw i64 %45, 1
%51 = icmp eq i64 %50, 20
br i1 %51, label %52, label %44
52: ; preds = %44
%53 = call i32 @putchar(i32 10)
%54 = call i32 @circular_buffer_pop(%struct.circular_buffer* %7, i8* %4, i64* %3)
%55 = load i64, i64* %3
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %55, i8* %4)
ret i32 0
}