#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*/ buffer;

/* Variables and functions */
int char_location(char *, char const);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ terminate_at_location(char *, int);
void typewriter(const char terminate) {
  printf("typewriter app\n");
  int loc;
  char buffer[4096];
  do {
    fgets(buffer, sizeof(buffer), stdin);
    loc = char_location(buffer, terminate);
    if (loc != -1) {
      terminate_at_location(buffer, loc);
    }
  } while (loc == -1);
}


x86 assembly (clang, -O0):
<typewriter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1050 <fgets@plt>
lea    -0x1010(%rbp),%rdi
movsbl -0x1(%rbp),%esi
call   1030 <char_location@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11a3 <typewriter+0x63>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <terminate_at_location@plt>
jmp    11a8 <typewriter+0x68>
cmpl   $0xffffffff,-0x8(%rbp)
je     115d <typewriter+0x1d>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<typewriter>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edi,%ebp
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e88(%rip),%r14
mov    %rsp,%rbx
movsbl %bpl,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <char_location@plt>
cmp    $0xffffffff,%eax
je     1170 <typewriter+0x30>
mov    %rsp,%rdi
mov    %eax,%esi
call   1060 <terminate_at_location@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"typewriter app\0A\00"
@stdin = global i32 0
define void @typewriter(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [4096 x i8]
store i8 %0, i8* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %20, %1
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 4096, i32 %8)
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = load i8, i8* %2
%12 = call i32 @char_location(i8* %10, i8 signext %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %6
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 @terminate_at_location(i8* %16, i32 %17)
br label %19
19: ; preds = %15, %6
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %6, label %23
23: ; preds = %20
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [15 x i8] c"typewriter app\00"
define void @typewriter(i8 signext %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %5, %1
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 4096, i32 %6)
%8 = call i32 @char_location(i8* %4, i8 signext %0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = call i32 @terminate_at_location(i8* %4, i32 %8)
ret void
}