#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 */
unsigned int computeIndex(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char text[1];
  while (1) {
    printf("String: ");
    scanf("%s", text);
    unsigned idx = computeIndex(text, 22);
    printf("Index(%s) = %u\n", text, idx);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x5(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1040 <scanf@plt>
lea    -0x5(%rbp),%rdi
mov    $0x16,%esi
call   1050 <computeIndex@plt>
mov    %eax,-0xc(%rbp)
lea    -0x5(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%r14
lea    0xec3(%rip),%r15
lea    0x7(%rsp),%rbx
lea    0xeba(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    $0x16,%esi
call   1050 <computeIndex@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1160 <main+0x30>

LLVM IR (-O0):
@.str = [9 x i8] c"String: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"Index(%s) = %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x i8]
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %0, %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%9 = call i32 @computeIndex(i8* %8, i32 22)
store i32 %9, i32* %3
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %11)
br label %4
}

LLVM IR (-O2):
@.str = [9 x i8] c"String: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"Index(%s) = %u\0A\00"
define i32 @main() {
%1 = alloca [1 x i8]
%2 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i32 @computeIndex(i8* %2, i32 22)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %6)
br label %3
}