#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 /*<<< orphan*/ feof(int /*<<< orphan*/);
unsigned char getchar();
scalar_t__ isupper(unsigned char);
int /*<<< orphan*/ putchar(unsigned char);
int /*<<< orphan*/ stdin;
unsigned char tolower(unsigned char);
void tolower_stdin(void) {
  unsigned char c = getchar();
  while (!feof(stdin)) {
    if (isupper(c)) {
      c = tolower(c);
    }
    putchar(c);
    c = getchar();
  }
}


x86 assembly (clang, -O0):
<tolower_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1185 <tolower_stdin+0x35>
jmp    11bc <tolower_stdin+0x6c>
movzbl -0x1(%rbp),%edi
call   1070 <isupper@plt>
cmp    $0x0,%rax
je     11a4 <tolower_stdin+0x54>
movzbl -0x1(%rbp),%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
jmp    1162 <tolower_stdin+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tolower_stdin>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    0x2e84(%rip),%r14
jmp    1181 <tolower_stdin+0x31>
cs nopw 0x0(%rax,%rax,1)
movzbl %bl,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1050 <feof@plt>
test   %eax,%eax
jne    11a7 <tolower_stdin+0x57>
movzbl %bl,%ebp
mov    %ebp,%edi
call   1070 <isupper@plt>
test   %rax,%rax
je     1170 <tolower_stdin+0x20>
mov    %ebp,%edi
call   1060 <tolower@plt>
mov    %eax,%ebx
jmp    1170 <tolower_stdin+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define void @tolower_stdin() {
%1 = alloca i8
%2 = call zeroext i8 (...) @getchar()
store i8 %2, i8* %1
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* @stdin
%5 = call i32 @feof(i32 %4)
%6 = icmp ne i32 %5, 0
%7 = xor i1 %6, true
br i1 %7, label %8, label %19
8: ; preds = %3
%9 = load i8, i8* %1
%10 = call i64 @isupper(i8 zeroext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8, i8* %1
%14 = call zeroext i8 @tolower(i8 zeroext %13)
store i8 %14, i8* %1
br label %15
15: ; preds = %12, %8
%16 = load i8, i8* %1
%17 = call i32 @putchar(i8 zeroext %16)
%18 = call zeroext i8 (...) @getchar()
store i8 %18, i8* %1
br label %3
19: ; preds = %3
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
define void @tolower_stdin() {
%1 = tail call zeroext i8 (...) @getchar()
%2 = load i32, i32* @stdin
%3 = tail call i32 @feof(i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0, %11
%6 = phi i8 [ %14, %11 ], [ %1, %0 ]
%7 = tail call i64 @isupper(i8 zeroext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call zeroext i8 @tolower(i8 zeroext %6)
br label %11
11: ; preds = %9, %5
%12 = phi i8 [ %10, %9 ], [ %6, %5 ]
%13 = tail call i32 @putchar(i8 zeroext %12)
%14 = tail call zeroext i8 (...) @getchar()
%15 = load i32, i32* @stdin
%16 = tail call i32 @feof(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %11, %0
ret void
}