#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 buf_put(char);
int get_input(char **, int);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int putter() {
  char *input;
  int input_length;
  int return_value;
  int i;
  printf("Any input will be sent to the receiving process through\n");
  printf("the circular buffer.\n");
  printf("Quit the program by entering \"q\" or \"Q\".\n");
  printf("\n");
  input = NULL;
  do {
    return_value = get_input(&input, 1024);
    if (return_value == -1) {
      printf("error, get_input\n");
    }
    input_length = strlen(input);
    for (i = 0; (i < input_length); i++) {
      do {
        return_value = buf_put(input[i]);
        if ((return_value != 1) && (return_value != 0)) {
          return -1;
        }
      } while (return_value == 0);
      if ((input[i] == 'q') || (input[i] == 'Q')) {
        break;
      }
    }
  } while ((input[i] != 'q') && (input[i] != 'Q'));
  return 0;
}


x86 assembly (clang, -O0):
<putter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
call   1040 <printf@plt>
lea    0xee8(%rip),%rdi
call   1040 <printf@plt>
lea    0xf04(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   1060 <get_input@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a7 <putter+0x67>
lea    0xed7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1250 <putter+0x110>
jmp    11cb <putter+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <buf_put@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     11ff <putter+0xbf>
cmpl   $0x0,-0x18(%rbp)
je     11ff <putter+0xbf>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <putter+0x156>
jmp    1204 <putter+0xc4>
cmpl   $0x0,-0x18(%rbp)
je     11cb <putter+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x71,%eax
je     1238 <putter+0xf8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x51,%eax
jne    123d <putter+0xfd>
jmp    1250 <putter+0x110>
jmp    1242 <putter+0x102>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <putter+0x7a>
jmp    1255 <putter+0x115>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x1d(%rbp)
je     1284 <putter+0x144>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x51,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1180 <putter+0x40>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%r15
lea    0xed7(%rip),%r14
mov    %r15,%rdi
mov    $0x400,%esi
call   1070 <get_input@plt>
cmp    $0xffffffff,%eax
jne    11b9 <putter+0x69>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1210 <putter+0xc0>
mov    %eax,%ebp
mov    %eax,%r12d
xor    %ebx,%ebx
xchg   %ax,%ax
mov    0x8(%rsp),%rax
movsbl (%rax,%rbx,1),%edi
call   1060 <buf_put@plt>
cmp    $0x1,%eax
ja     122c <putter+0xdc>
test   %eax,%eax
je     11d0 <putter+0x80>
mov    0x8(%rsp),%rax
movzbl (%rax,%rbx,1),%ecx
or     $0x20,%cl
cmp    $0x71,%cl
je     1228 <putter+0xd8>
add    $0x1,%rbx
cmp    %r12,%rbx
jne    11d0 <putter+0x80>
jmp    1217 <putter+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebp,%ebp
mov    0x8(%rsp),%rax
mov    %ebp,%ecx
mov    (%rax,%rcx,1),%al
or     $0x20,%al
cmp    $0x71,%al
jne    119f <putter+0x4f>
jmp    123e <putter+0xee>
mov    %ebx,%ebp
jmp    1217 <putter+0xc7>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1231 <putter+0xe1>

LLVM IR (-O0):
@.str = [57 x i8] c"Any input will be sent to the receiving process through\0A\00"
@.str.1 = [22 x i8] c"the circular buffer.\0A\00"
@.str.2 = [42 x i8] c"Quit the program by entering \22q\22 or \22Q\22.\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [18 x i8] c"error, get_input\0A\00"
define i32 @putter() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %10
10: ; preds = %79, %0
%11 = call i32 @get_input(i8** %2, i32 1024)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i8*, i8** %2
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %3
store i32 0, i32* %5
br label %19
19: ; preds = %59, %16
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %62
23: ; preds = %19
br label %24
24: ; preds = %38, %23
%25 = load i8*, i8** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @buf_put(i8 signext %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -1, i32* %1
br label %82
37: ; preds = %33, %24
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 0
br i1 %40, label %24, label %41
41: ; preds = %38
%42 = load i8*, i8** %2
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 113
br i1 %48, label %57, label %49
49: ; preds = %41
%50 = load i8*, i8** %2
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 81
br i1 %56, label %57, label %58
57: ; preds = %49, %41
br label %62
58: ; preds = %49
br label %59
59: ; preds = %58
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %19
62: ; preds = %57, %19
br label %63
63: ; preds = %62
%64 = load i8*, i8** %2
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 113
br i1 %70, label %71, label %79
71: ; preds = %63
%72 = load i8*, i8** %2
%73 = load i32, i32* %5
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp ne i32 %77, 81
br label %79
79: ; preds = %71, %63
%80 = phi i1 [ false, %63 ], [ %78, %71 ]
br i1 %80, label %10, label %81
81: ; preds = %79
store i32 0, i32* %1
br label %82
82: ; preds = %81, %36
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
@str = [56 x i8] c"Any input will be sent to the receiving process through\00"
@str.5 = [21 x i8] c"the circular buffer.\00"
@str.6 = [41 x i8] c"Quit the program by entering \22q\22 or \22Q\22.\00"
@str.7 = [17 x i8] c"error, get_input\00"
define i32 @putter() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
store i8* null, i8** %1
br label %7
7: ; preds = %39, %0
%8 = call i32 @get_input(i8** %1, i32 1024)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = load i8*, i8** %1
%14 = call i32 @strlen(i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = load i8*, i8** %1
br label %39
18: ; preds = %12
%19 = zext i32 %14 to i64
br label %20
20: ; preds = %18, %34
%21 = phi i64 [ 0, %18 ], [ %35, %34 ]
br label %22
22: ; preds = %20, %28
%23 = load i8*, i8** %1
%24 = getelementptr inbounds i8, i8* %23, i64 %21
%25 = load i8, i8* %24
%26 = call i32 @buf_put(i8 signext %25)
%27 = icmp ult i32 %26, 2
br i1 %27, label %28, label %45
28: ; preds = %22
%29 = icmp eq i32 %26, 0
br i1 %29, label %22, label %30
30: ; preds = %28
%31 = load i8*, i8** %1
%32 = getelementptr inbounds i8, i8* %31, i64 %21
%33 = load i8, i8* %32
switch i8 %33, label %34 [
i8 113, label %37
i8 81, label %37
]
34: ; preds = %30
%35 = add nuw nsw i64 %21, 1
%36 = icmp eq i64 %35, %19
br i1 %36, label %39, label %20
37: ; preds = %30, %30
%38 = trunc i64 %21 to i32
br label %39
39: ; preds = %34, %37, %16
%40 = phi i8* [ %17, %16 ], [ %31, %37 ], [ %31, %34 ]
%41 = phi i32 [ 0, %16 ], [ %38, %37 ], [ %14, %34 ]
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
switch i8 %44, label %7 [
i8 113, label %45
i8 81, label %45
]
45: ; preds = %39, %39, %22
%46 = phi i32 [ -1, %22 ], [ 0, %39 ], [ 0, %39 ]
ret i32 %46
}