#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
main() {
  int i = 0;
  int j = 0;
  int length = 1000;
  char p, text[length];
  FILE *fp;
  fp = fopen("text", "r");
  fgets(text, length, fp);
  for (i = 0; i < length; i++) {
    if (text[i] == 0) {
      printf("\n");
      break;
    }
    printf("%c", text[i]);
  }
  printf("mojisitei: ");
  scanf("%c", &p);
  for (i = 0; i < length; i++) {
    if (text[i] == 0) {
      break;
    }
    if (text[i] == p) {
      j++;
    }
  }
  printf("%d\n", j);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x3e8,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1040 <fgets@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1214 <main+0xd4>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11ec <main+0xac>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xd4>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b8 <main+0x78>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdde(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1293 <main+0x153>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    125f <main+0x11f>
jmp    1293 <main+0x153>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1280 <main+0x140>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1285 <main+0x145>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1239 <main+0xf9>
mov    -0xc(%rbp),%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %rsp,%r14
lea    0xe9c(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x10(%rsp,%rbx,1),%edi
test   %edi,%edi
je     11ad <main+0x5d>
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1190 <main+0x40>
jmp    11b7 <main+0x67>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe4c(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe39(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%eax
mov    0xf(%rsp),%cl
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xf(%rsp,%rax,1),%edx
test   %dl,%dl
je     1222 <main+0xd2>
xor    %esi,%esi
cmp    %cl,%dl
sete   %sil
add    %esi,%ebx
movzbl 0x10(%rsp,%rax,1),%edx
test   %dl,%dl
je     1222 <main+0xd2>
xor    %esi,%esi
cmp    %cl,%dl
sete   %sil
add    %esi,%ebx
add    $0x2,%rax
cmp    $0x3e9,%rax
jne    11f0 <main+0xa0>
lea    0xded(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"text\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [12 x i8] c"mojisitei: \00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 1000, i32* %4
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32, i32* %4
%15 = load i32*, i32** %8
%16 = call i32 @fgets(i8* %12, i32 %14, i32* %15)
store i32 0, i32* %2
br label %17
17: ; preds = %37, %0
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %12, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %40
30: ; preds = %21
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %12, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %17
40: ; preds = %28, %17
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
store i32 0, i32* %2
br label %43
43: ; preds = %68, %40
%44 = load i32, i32* %2
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %71
47: ; preds = %43
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %12, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %47
br label %71
55: ; preds = %47
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %12, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = load i8, i8* %5
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %60, %62
br i1 %63, label %64, label %67
64: ; preds = %55
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 1
store i32 %66, i32* %3
br label %67
67: ; preds = %64, %55
br label %68
68: ; preds = %67
%69 = load i32, i32* %2
%70 = add nsw i32 %69, 1
store i32 %70, i32* %2
br label %43
71: ; preds = %54, %43
%72 = load i32, i32* %3
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %72)
%74 = load i8*, i8** %6
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@.str = [5 x i8] c"text\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [12 x i8] c"mojisitei: \00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i8* @llvm.stacksave()
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fgets(i8* %4, i32 1000, i32* %5)
br label %7
7: ; preds = %0, %14
%8 = phi i64 [ 0, %0 ], [ %17, %14 ]
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @putchar(i32 10)
br label %19
14: ; preds = %7
%15 = sext i8 %10 to i32
%16 = call i32 @putchar(i32 %15)
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, 1000
br i1 %18, label %19, label %7
19: ; preds = %14, %12
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%22 = load i8, i8* %1
br label %23
23: ; preds = %37, %19
%24 = phi i64 [ 0, %19 ], [ %41, %37 ]
%25 = phi i32 [ 0, %19 ], [ %40, %37 ]
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %24
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %43, label %29
29: ; preds = %23
%30 = icmp eq i8 %27, %22
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %25, %31
%33 = or i64 %24, 1
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %29
%38 = icmp eq i8 %35, %22
%39 = zext i1 %38 to i32
%40 = add nuw nsw i32 %32, %39
%41 = add nuw nsw i64 %24, 2
%42 = icmp eq i64 %41, 1000
br i1 %42, label %43, label %23
43: ; preds = %37, %29, %23
%44 = phi i32 [ %25, %23 ], [ %32, %29 ], [ %40, %37 ]
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
ret i32 0
}