#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 *);
char *strchr(char *, char);
int main() {
  char str[] = "abcdefghijklmnopqrstuvwxyz";
  char look;
  char *pos;
  pos = strchr(str, 'e');
  printf("Character 'e' found at position %d.\n\n", pos - str);
  printf("Specify character to look for: ");
  scanf("%c", &look);
  pos = strchr(str, look);
  if (pos == NULL)
    printf("Character '%c' could not be found.\n\n", look);
  else
    printf("Character '%c' was found at position %d.\n\n", look, pos - str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb1(%rip),%ax
mov    %ax,-0x8(%rbp)
mov    0xea9(%rip),%al
mov    %al,-0x6(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x65,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rax
sub    %rax,%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0x21(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x20(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f0 <main+0xc0>
movsbl -0x21(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120d <main+0xdd>
movsbl -0x21(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rax
sub    %rax,%rdx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movups 0xece(%rip),%xmm0
movups %xmm0,0x1b(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x65,%esi
call   1030 <strchr@plt>
sub    %rbx,%rax
lea    0xeb1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bf <main+0x8f>
sub    %rbx,%rax
lea    0xed8(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cf <main+0x9f>
lea    0xe9e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str = [38 x i8] c"Character 'e' found at position %d.\0A\0A\00"
@.str.1 = [32 x i8] c"Specify character to look for: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [37 x i8] c"Character '%c' could not be found.\0A\0A\00"
@.str.4 = [43 x i8] c"Character '%c' was found at position %d.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [27 x i8]
%3 = alloca i8
%4 = alloca i8*
store i32 0, i32* %1
%5 = bitcast [27 x i8]* %2 to i8*
%6 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%7 = call i8* @strchr(i8* %6, i8 signext 101)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%10 = ptrtoint i8* %8 to i64
%11 = ptrtoint i8* %9 to i64
%12 = sub i64 %10, %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%16 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%17 = load i8, i8* %3
%18 = call i8* @strchr(i8* %16, i8 signext %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %0
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %34
25: ; preds = %0
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = load i8*, i8** %4
%29 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %27, i64 %32)
br label %34
34: ; preds = %25, %21
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str = [38 x i8] c"Character 'e' found at position %d.\0A\0A\00"
@.str.1 = [32 x i8] c"Specify character to look for: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [37 x i8] c"Character '%c' could not be found.\0A\0A\00"
@.str.4 = [43 x i8] c"Character '%c' was found at position %d.\0A\0A\00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%4 = call i8* @strchr(i8* %3, i8 signext 101)
%5 = ptrtoint i8* %4 to i64
%6 = ptrtoint [27 x i8]* %1 to i64
%7 = sub i64 %5, %6
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = load i8, i8* %2
%12 = call i8* @strchr(i8* %3, i8 signext %11)
%13 = icmp eq i8* %12, null
%14 = sext i8 %11 to i32
br i1 %13, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %21
17: ; preds = %0
%18 = ptrtoint i8* %12 to i64
%19 = sub i64 %18, %6
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %14, i64 %19)
br label %21
21: ; preds = %17, %15
ret i32 0
}