#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ system(char *);
void ex3() {
  char phrase[30];
  printf("Type a phrase: ");
  fgets(phrase, 30, stdin);
  phrase[strlen(phrase) - 1] = phrase[strlen(phrase)];
  system("clear");
  for (int k = 0; k < strlen(phrase); k++) {
    printf("||  %c  ||  %d  ||  %d ||\n", phrase[k], k, (int)phrase[k]);
  }
}


x86 assembly (clang, -O0):
<ex3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1060 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    -0x20(%rbp,%rax,1),%al
mov    %al,-0x25(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x25(%rbp),%cl
sub    $0x1,%eax
cltq
mov    %cl,-0x20(%rbp,%rax,1)
lea    0xe75(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11f4 <ex3+0xb4>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
mov    -0x24(%rbp),%edx
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a7 <ex3+0x67>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex3>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
mov    (%rsp,%rax,1),%bl
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
mov    %bl,-0x1(%rax,%r14,1)
lea    0xe7d(%rip),%rdi
call   1040 <system@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d5 <ex3+0x95>
lea    0xe6b(%rip),%r14
mov    %rsp,%r15
xor    %ebx,%ebx
movsbl (%rsp,%rbx,1),%ecx
mov    %r14,%rdi
mov    %ecx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11b0 <ex3+0x70>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Type a phrase: \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"clear\00"
@.str.2 = [27 x i8] c"|| %c || %d || %d ||\0A\00"
define void @ex3() {
%1 = alloca [30 x i8]
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 30, i32 %5)
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %15
store i8 %11, i8* %16
%17 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %18
18: ; preds = %36, %0
%19 = load i32, i32* %2
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %2
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29, i32 %34)
br label %36
36: ; preds = %23
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %18
39: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Type a phrase: \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"clear\00"
@.str.2 = [27 x i8] c"|| %c || %d || %d ||\0A\00"
define void @ex3() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 30, i32 %4)
%6 = call i32 @strlen(i8* %2)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = call i32 @strlen(i8* %2)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %12
store i8 %9, i8* %13
%14 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @strlen(i8* %2)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %18, %0
ret void
18: ; preds = %0, %18
%19 = phi i64 [ %25, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = trunc i64 %19 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23, i32 %22)
%25 = add nuw nsw i64 %19, 1
%26 = call i32 @strlen(i8* %2)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %18, label %17
}