#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 EOF;
int buf_get(char *);
int fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int getter() {
  char c;
  int return_value;
  printf("The characters read from the circular buffer will be printed.\n");
  printf("The program will terminate when the \"q\" or \"Q\" character\n");
  printf("is read from the buffer.\n");
  printf("\n");
  do {
    do {
      return_value = buf_get(&c);
      if ((return_value != 1) && (return_value != 0)) {
        return -1;
      }
    } while (return_value == 0);
    printf("%c", c);
    return_value = fflush(stdout);
    if (return_value == EOF) {
      perror("error, fflush");
      return -1;
    }
  } while ((c != 'q') && (c != 'Q'));
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<getter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1185 <getter+0x45>
lea    -0x5(%rbp),%rdi
call   1040 <buf_get@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11b1 <getter+0x71>
cmpl   $0x0,-0xc(%rbp)
je     11b1 <getter+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <getter+0x111>
jmp    11b6 <getter+0x76>
cmpl   $0x0,-0xc(%rbp)
je     1185 <getter+0x45>
movsbl -0x5(%rbp),%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
jne    120d <getter+0xcd>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <getter+0x111>
jmp    1212 <getter+0xd2>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0xd(%rbp)
je     1231 <getter+0xf1>
movsbl -0x5(%rbp),%eax
cmp    $0x51,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1180 <getter+0x40>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
lea    0xf0f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x7(%rsp),%rbx
mov    0x2e47(%rip),%r14
mov    0x2e50(%rip),%r15
mov    $0xffffffff,%ebp
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <buf_get@plt>
cmp    $0x1,%eax
ja     11df <getter+0x8f>
test   %eax,%eax
je     11a0 <getter+0x50>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    (%r14),%edi
call   1060 <fflush@plt>
cmp    (%r15),%eax
je     11ec <getter+0x9c>
movzbl 0x7(%rsp),%eax
and    $0xdf,%al
cmp    $0x51,%al
jne    11a0 <getter+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
jmp    11df <getter+0x8f>

LLVM IR (-O0):
@.str = [63 x i8] c"The characters read from the circular buffer will be printed.\0A\00"
@.str.1 = [58 x i8] c"The program will terminate when the \22q\22 or \22Q\22 character\0A\00"
@.str.2 = [26 x i8] c"is read from the buffer.\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@stdout = global i32 0
@EOF = global i32 0
@.str.5 = [14 x i8] c"error, fflush\00"
define i32 @getter() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %41, %0
br label %9
9: ; preds = %18, %8
%10 = call i32 @buf_get(i8* %2)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %1
br label %45
17: ; preds = %13, %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %9, label %21
21: ; preds = %18
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %45
32: ; preds = %21
br label %33
33: ; preds = %32
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 113
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8, i8* %2
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 81
br label %41
41: ; preds = %37, %33
%42 = phi i1 [ false, %33 ], [ %40, %37 ]
br i1 %42, label %8, label %43
43: ; preds = %41
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %45
45: ; preds = %43, %30, %16
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i32 0
@.str.5 = [14 x i8] c"error, fflush\00"
@str = [62 x i8] c"The characters read from the circular buffer will be printed.\00"
@str.6 = [57 x i8] c"The program will terminate when the \22q\22 or \22Q\22 character\00"
@str.7 = [25 x i8] c"is read from the buffer.\00"
define i32 @getter() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.6, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i32 @putchar(i32 10)
br label %6
6: ; preds = %11, %0
%7 = call i32 @buf_get(i8* %1)
%8 = icmp ult i32 %7, 2
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = icmp eq i32 %7, 0
br i1 %10, label %11, label %12
11: ; preds = %9, %22
br label %6
12: ; preds = %9
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = call i32 @putchar(i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %28
22: ; preds = %12
%23 = load i8, i8* %1
%24 = and i8 %23, -33
%25 = icmp eq i8 %24, 81
br i1 %25, label %26, label %11
26: ; preds = %22
%27 = call i32 @putchar(i32 10)
br label %28
28: ; preds = %6, %26, %20
%29 = phi i32 [ -1, %20 ], [ 0, %26 ], [ -1, %6 ]
ret i32 %29
}