#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char userString[25];
  char userInput;
  int stringLength;
  printf("Welcome to the String Scanner!");
  printf("\nHere you will be entering a string, and we will tell you the "
         "location of each character in the array!");
  do {
    printf("\n\nPlease enter a string:");
    scanf("%s", userString);
    stringLength = strlen(userString);
    for (int counter = 0; counter < stringLength; counter++) {
      printf("\nThe character at byte %d is: %c", counter, userString[counter]);
    }
    printf("\n\nThat was fun! Type 'y' to do it again!");
    scanf(" %c", &userInput);
  } while (userInput == 'y' || userInput == 'Y');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xf2b(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11c0 <main+0x90>
mov    -0x2c(%rbp),%esi
movslq -0x2c(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%edx
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118c <main+0x5c>
lea    0xefc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
lea    -0x21(%rbp),%rsi
call   1050 <scanf@plt>
movsbl -0x21(%rbp),%ecx
mov    $0x1,%al
cmp    $0x79,%ecx
mov    %al,-0x2d(%rbp)
je     11fd <main+0xcd>
movsbl -0x21(%rbp),%eax
cmp    $0x59,%eax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    115b <main+0x2b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%r12
lea    0xf3c(%rip),%rbx
lea    0xf52(%rip),%rbp
lea    0xf(%rsp),%r14
jmp    11a3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf3c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0xf(%rsp),%al
and    $0xdf,%al
cmp    $0x59,%al
jne    11fe <main+0xce>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee7(%rip),%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1180 <main+0x50>
mov    %eax,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x10(%rsp,%r15,1),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    11e0 <main+0xb0>
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Welcome to the String Scanner!\00"
@.str.1 = [103 x i8] c"\0AHere you will be entering a string, and we will tell you the location of each character in the array!\00"
@.str.2 = [25 x i8] c"\0A\0APlease enter a string:\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [33 x i8] c"\0AThe character at byte %d is: %c\00"
@.str.5 = [41 x i8] c"\0A\0AThat was fun! Type 'y' to do it again!\00"
@.str.6 = [4 x i8] c" %c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [25 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %40, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %4
store i32 0, i32* %5
br label %14
14: ; preds = %26, %8
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %24)
br label %26
26: ; preds = %18
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %14
29: ; preds = %14
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %3)
br label %32
32: ; preds = %29
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 121
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 89
br label %40
40: ; preds = %36, %32
%41 = phi i1 [ true, %32 ], [ %39, %36 ]
br i1 %41, label %8, label %42
42: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Welcome to the String Scanner!\00"
@.str.1 = [103 x i8] c"\0AHere you will be entering a string, and we will tell you the location of each character in the array!\00"
@.str.2 = [25 x i8] c"\0A\0APlease enter a string:\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [33 x i8] c"\0AThe character at byte %d is: %c\00"
@.str.5 = [41 x i8] c"\0A\0AThat was fun! Type 'y' to do it again!\00"
@.str.6 = [4 x i8] c" %c\00"
define i32 @main() {
%1 = alloca [25 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %13, %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%9 = call i32 @strlen(i8* %3)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = zext i32 %9 to i64
br label %19
13: ; preds = %19, %6
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%16 = load i8, i8* %2
%17 = and i8 %16, -33
%18 = icmp eq i8 %17, 89
br i1 %18, label %6, label %28
19: ; preds = %11, %19
%20 = phi i64 [ 0, %11 ], [ %26, %19 ]
%21 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = trunc i64 %20 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %23)
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %13, label %19
28: ; preds = %13
ret i32 0
}