#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int getchar();
scalar_t__ isupper(int);
int putchar(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int tolower(int);
int main(void) {
  int c;
  while ((c = getchar()) != EOF) {
    if (isupper(c))
      c = tolower(c);
    if (putchar(c) == EOF) {
      fprintf(stderr, "Err: %d putchar() - %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
    if (c == '\n')
      fflush(stdout);
    if (c == 'q')
      break;
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
je     1251 <main+0xd1>
mov    -0x8(%rbp),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     11c5 <main+0x45>
mov    -0x8(%rbp),%edi
call   1060 <tolower@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%eax
jne    1225 <main+0xa5>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    %rax,%rcx
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0xa,-0x8(%rbp)
jne    123d <main+0xbd>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
cmpl   $0x71,-0x8(%rbp)
jne    124c <main+0xcc>
jmp    1251 <main+0xd1>
jmp    118f <main+0xf>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e56(%rip),%rbp
cmp    0x0(%rbp),%eax
je     11f1 <main+0x71>
mov    %eax,%ebx
mov    0x2e20(%rip),%r14
jmp    11c6 <main+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%edi
call   1070 <fflush@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    0x0(%rbp),%eax
je     11f1 <main+0x71>
mov    %ebx,%edi
call   1080 <isupper@plt>
test   %rax,%rax
je     11db <main+0x5b>
mov    %ebx,%edi
call   1060 <tolower@plt>
mov    %eax,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
cmp    0x0(%rbp),%eax
je     11ff <main+0x7f>
cmp    $0xa,%ebx
je     11b0 <main+0x30>
cmp    $0x71,%ebx
jne    11b8 <main+0x38>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc1(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xde1(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Err: %d putchar() - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %37, %0
%4 = call i32 (...) @getchar()
store i32 %4, i32* %2
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %38
7: ; preds = %3
%8 = load i32, i32* %2
%9 = call i64 @isupper(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i32 @tolower(i32 %12)
store i32 %13, i32* %2
br label %14
14: ; preds = %11, %7
%15 = load i32, i32* %2
%16 = call i32 @putchar(i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %14
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 113
br i1 %35, label %36, label %37
36: ; preds = %33
br label %38
37: ; preds = %33
br label %3
38: ; preds = %36, %3
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Err: %d putchar() - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %30, label %4
4: ; preds = %0, %23
%5 = phi i32 [ %24, %23 ], [ %1, %0 ]
%6 = tail call i64 @isupper(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @tolower(i32 %5)
br label %10
10: ; preds = %8, %4
%11 = phi i32 [ %9, %8 ], [ %5, %4 ]
%12 = tail call i32 @putchar(i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
switch i32 %11, label %23 [
i32 10, label %27
i32 113, label %30
]
23: ; preds = %22, %27
%24 = tail call i32 (...) @getchar()
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %30, label %4
27: ; preds = %22
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
br label %23
30: ; preds = %23, %22, %0
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}