#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 count(char *, char *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
main() {
  int i;
  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);
  printf("%d\n", count(&p, text, length));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%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    0xe66(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1050 <fgets@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    121d <main+0xcd>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11f5 <main+0xa5>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121d <main+0xcd>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c1 <main+0x71>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd5(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    -0x11(%rbp),%rdi
call   1030 <count@plt>
mov    %eax,%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <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    0xe8c(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x10(%rsp,%rbx,1),%edi
test   %edi,%edi
je     11bd <main+0x5d>
call   1040 <putchar@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    11a0 <main+0x40>
jmp    11c7 <main+0x67>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe2b(%rip),%rdi
lea    0xf(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3e8,%edx
call   1030 <count@plt>
lea    0xe14(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <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* %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)
%43 = load i32, i32* %4
%44 = call i32 @count(i8* %5, i8* %12, i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = load i8*, i8** %6
%47 = load i32, i32* %1
ret i32 %47
}

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 = call i32 @count(i8* %1, i8* %4, i32 1000)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %22)
ret i32 0
}