#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
void iniee(int num, int sum) {
  FILE *fp;
  int n = 0;
  char s[2000];
  fp = fopen("data/ec.db", "r");
  while (n < sum) {
    s[n++] = fgetc(fp);
  }
  s[num - 1] = '0';
  fclose(fp);
  fp = fopen("data/ec.db", "w");
  for (n = 0; n < sum; n++)
    fprintf(fp, "%c", s[n]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<iniee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119f <iniee+0x5f>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0x7f0(%rbp,%rax,1)
jmp    116f <iniee+0x2f>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x30,-0x7f0(%rbp,%rax,1)
30
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe41(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120c <iniee+0xcc>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
lea    0xe1e(%rip),%rsi
movsbl -0x7f0(%rbp,%rax,1),%edx
ff
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <iniee+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniee>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7d0,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0xea4(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %r15d,%ebx
test   %r15d,%r15d
jle    1194 <iniee+0x54>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <iniee+0x40>
movslq %r14d,%rax
mov    %rsp,%rcx
movb   $0x30,-0x1(%rax,%rcx,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe52(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11e5 <iniee+0xa5>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbp,1),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <iniee+0x90>
mov    %r14,%rdi
add    $0x7d0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

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