#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 *);
void main() {
  char str[20], *ps;
  int i;
  printf("Input a string: ");
  ps = str;
  scanf("%s", ps);
  for (i = 0; ps[i] != '\0'; i++) {
    if (ps[i] == 'k') {
      printf("There is a key in the string!\n");
      break;
    }
  }
  if (ps[i] == '\0')
    printf("There is no key in the string\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xeca(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a1 <main+0x81>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6b,%eax
jne    118e <main+0x6e>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
jmp    11a1 <main+0x81>
jmp    1193 <main+0x73>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <main+0x33>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11c2 <main+0xa2>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec4(%rip),%rdi
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsp,%rax,1),%ecx
test   %cl,%cl
je     1187 <main+0x57>
cmp    $0x6b,%cl
je     1173 <main+0x43>
add    $0x1,%rax
jmp    1160 <main+0x30>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x0,(%rsp,%rbx,1)
jne    1193 <main+0x63>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Input a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [31 x i8] c"There is a key in the string!\0A\00"
@.str.3 = [31 x i8] c"There is no key in the string\0A\00"
define void @main() {
%1 = alloca [20 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
store i32 0, i32* %3
br label %8
8: ; preds = %27, %0
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %8
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 107
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %30
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %8
30: ; preds = %24, %8
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Input a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@str = [30 x i8] c"There is no key in the string\00"
@str.4 = [30 x i8] c"There is a key in the string!\00"
define void @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %5
5: ; preds = %9, %0
%6 = phi i64 [ %10, %9 ], [ 0, %0 ]
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 0, label %17
i8 107, label %11
]
9: ; preds = %5
%10 = add nuw i64 %6, 1
br label %5
11: ; preds = %5
%12 = and i64 %6, 4294967295
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %12
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
%15 = load i8, i8* %13
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5, %11
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
ret void
}