#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int tolower(char);
int toupper(char);
int main() {
  int i = 0;
  char s[100];
  printf("Enter a line of text: ");
  gets(s);
  while (s[i] != '\0')
    printf("%c", tolower(s[i++]));
  printf("\n");
  i = 0;
  while (s[i] != '\0')
    printf("%c", toupper(s[i++]));
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <gets@plt>
movslq -0x8(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11ab <main+0x6b>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
movsbl -0x70(%rbp,%rax,1),%edi
call   1060 <tolower@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116d <main+0x2d>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11fe <main+0xbe>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <toupper@plt>
mov    %eax,%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c0 <main+0x80>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1060 <gets@plt>
mov    (%rsp),%al
test   %al,%al
je     119a <main+0x4a>
lea    0x1(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1070 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%al
test   %al,%al
je     11ca <main+0x7a>
lea    0x1(%rsp),%rbx
movsbl %al,%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Enter a line of text: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @tolower(i8 signext %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %7
22: ; preds = %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %24
24: ; preds = %31, %22
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %24
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @toupper(i8 signext %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %24
39: ; preds = %24
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Enter a line of text: \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %10, %7 ], [ 0, %0 ]
%9 = phi i8 [ %14, %7 ], [ %5, %0 ]
%10 = add nuw i64 %8, 1
%11 = call i32 @tolower(i8 signext %9)
%12 = call i32 @putchar(i32 %11)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %0
%17 = call i32 @putchar(i32 10)
%18 = load i8, i8* %2
%19 = icmp eq i8 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16, %20
%21 = phi i64 [ %23, %20 ], [ 0, %16 ]
%22 = phi i8 [ %27, %20 ], [ %18, %16 ]
%23 = add nuw i64 %21, 1
%24 = call i32 @toupper(i8 signext %22)
%25 = call i32 @putchar(i32 %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %23
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %20, %16
%30 = call i32 @putchar(i32 10)
ret i32 0
}