#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
void initi(char s[], char m[]) {
  char c, sum[2000];
  int n = 0, num = 0;
  FILE *fp;
  fp = fopen(s, "r");
  while ((c = fgetc(fp)) != EOF)
    if (c == '^')
      num++;
  fp = fopen(m, "w");
  while (n < num) {
    sum[n++] = '0';
  }
  for (n = 0; n < num; n++)
    fprintf(fp, "%c", sum[n]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<initi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x7f4(%rbp)
movl   $0x0,-0x7f8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x800(%rbp)
mov    -0x800(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e51(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c3 <initi+0x83>
movsbl -0x11(%rbp),%eax
cmp    $0x5e,%eax
jne    11be <initi+0x7e>
mov    -0x7f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f8(%rbp)
jmp    117e <initi+0x3e>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x800(%rbp)
mov    -0x7f4(%rbp),%eax
cmp    -0x7f8(%rbp),%eax
jge    120c <initi+0xcc>
mov    -0x7f4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7f4(%rbp)
cltq
movb   $0x30,-0x7f0(%rbp,%rax,1)
30
jmp    11da <initi+0x9a>
movl   $0x0,-0x7f4(%rbp)
mov    -0x7f4(%rbp),%eax
cmp    -0x7f8(%rbp),%eax
jge    125e <initi+0x11e>
mov    -0x800(%rbp),%rdi
movslq -0x7f4(%rbp),%rax
lea    0xdc7(%rip),%rsi
movsbl -0x7f0(%rbp,%rax,1),%edx
ff
call   1050 <fprintf@plt>
mov    -0x7f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f4(%rbp)
jmp    1216 <initi+0xd6>
mov    -0x800(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x7d8,%rsp
mov    %rsi,%r14
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e6a(%rip),%r15
cmp    (%r15),%al
jne    1197 <initi+0x47>
lea    0xe78(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
jmp    11f5 <initi+0xa5>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0x5e,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11a0 <initi+0x50>
lea    0xe45(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     11f5 <initi+0xa5>
mov    %ebp,%ebx
mov    %rsp,%rdi
mov    $0x30,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
xor    %ebp,%ebp
movsbl (%rsp,%rbp,1),%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11e0 <initi+0x90>
mov    %r14,%rdi
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%c\00"
define void @initi(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca [2000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
br label %12
12: ; preds = %26, %2
%13 = load i32*, i32** %9
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %5
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 94
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %26
26: ; preds = %23, %19
br label %12
27: ; preds = %12
%28 = load i8*, i8** %4
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
br label %30
30: ; preds = %34, %27
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 %37
store i8 48, i8* %38
br label %30
39: ; preds = %30
store i32 0, i32* %7
br label %40
40: ; preds = %51, %39
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i32*, i32** %9
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %40
54: ; preds = %40
%55 = load i32*, i32** %9
%56 = call i32 @fclose(i32* %55)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [2 x i8] c"w\00"
define void @initi(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [2000 x i8]
%4 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call signext i8 @fgetc(i32* %6)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %35
12: ; preds = %2, %12
%13 = phi i8 [ %18, %12 ], [ %7, %2 ]
%14 = phi i32 [ %17, %12 ], [ 0, %2 ]
%15 = icmp eq i8 %13, 94
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %14, %16
%18 = tail call signext i8 @fgetc(i32* %6)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %12
%22 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32 %17, 0
br i1 %23, label %35, label %24
24: ; preds = %21
%25 = zext i32 %17 to i64
%26 = zext i32 %17 to i64
br label %27
27: ; preds = %24, %27
%28 = phi i64 [ 0, %24 ], [ %33, %27 ]
%29 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = tail call i32 @fputc(i32 %31, i32* %22)
%33 = add nuw nsw i64 %28, 1
%34 = icmp eq i64 %33, %26
br i1 %34, label %35, label %27
35: ; preds = %27, %21, %10
%36 = phi i32* [ %22, %21 ], [ %11, %10 ], [ %22, %27 ]
%37 = tail call i32 @fclose(i32* %36)
ret void
}