#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*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, float);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int *malloc(int);
int main(int argc, char *argv[]) {
  int *arr = malloc(27770 * sizeof(int));
  FILE *id_file = fopen("data/map.txt", "r");
  int i;
  int number;
  float similarity;
  for (i = 0; i < 27770; i++)
    fscanf(id_file, "%d", &arr[i]);
  fclose(id_file);
  FILE *new_data_file = fopen("data/final.txt", "w");
  FILE *old_data_file = fopen("data/similar.txt", "r");
  while (!feof(old_data_file)) {
    fscanf(old_data_file, "%d", &number);
    fprintf(new_data_file, "%d ", arr[number]);
    fscanf(old_data_file, "%d", &number);
    fprintf(new_data_file, "%d ", arr[number]);
    fscanf(old_data_file, "%f", &similarity);
    fprintf(new_data_file, "%f\n", similarity);
  }
  fclose(new_data_file);
  fclose(old_data_file);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1b1e8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe65(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x6c7a,-0x24(%rbp)
jge    11ee <main+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <main+0x42>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe14(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe0e(%rip),%rdi
lea    0xdf1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1243 <main+0xd3>
jmp    12d9 <main+0x169>
mov    -0x40(%rbp),%rdi
lea    0xdc1(%rip),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
lea    0xdc3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd8e(%rip),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
lea    0xd90(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd84(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x38(%rbp),%rdi
movss  -0x2c(%rbp),%xmm0
lea    0xd6c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1225 <main+0xb5>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1b1e8,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe71(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe6a(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbp,1),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fscanf@plt>
add    $0x4,%rbp
cmp    $0x1b1e8,%rbp
jne    11b0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe35(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe30(%rip),%rdi
lea    0xe13(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    12bb <main+0x14b>
lea    0xdf6(%rip),%r12
mov    %rsp,%r13
lea    0xe11(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
movslq (%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2ssl (%r15,%rax,4),%xmm0
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
movslq (%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2ssl (%r15,%rax,4),%xmm0
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
lea    0xdae(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
movss  0x4(%rsp),%xmm0
mov    %r14,%rdi
lea    0xd95(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1230 <main+0xc0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"data/map.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [15 x i8] c"data/final.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [17 x i8] c"data/similar.txt\00"
@.str.6 = [4 x i8] c"%d \00"
@.str.7 = [3 x i8] c"%f\00"
@.str.8 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32* @malloc(i32 111080)
store i32* %13, i32** %6
%14 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
store i32 0, i32* %8
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 27770
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32*, i32** %7
%20 = load i32*, i32** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 (i32*, i8*, ...) @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %15
28: ; preds = %15
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
%31 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %11
%32 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %12
br label %33
33: ; preds = %38, %28
%34 = load i32*, i32** %12
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %64
38: ; preds = %33
%39 = load i32*, i32** %12
%40 = call i32 (i32*, i8*, ...) @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%41 = load i32*, i32** %11
%42 = load i32*, i32** %6
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = sitofp i32 %46 to float
%48 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), float %47)
%49 = load i32*, i32** %12
%50 = call i32 (i32*, i8*, ...) @fscanf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%51 = load i32*, i32** %11
%52 = load i32*, i32** %6
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = sitofp i32 %56 to float
%58 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), float %57)
%59 = load i32*, i32** %12
%60 = call i32 (i32*, i8*, ...) @fscanf(i32* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), float* %10)
%61 = load i32*, i32** %11
%62 = load float, float* %10
%63 = call i32 @fprintf(i32* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), float %62)
br label %33
64: ; preds = %33
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = load i32*, i32** %12
%68 = call i32 @fclose(i32* %67)
%69 = load i32*, i32** %6
%70 = call i32 @free(i32* %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"data/map.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [15 x i8] c"data/final.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [17 x i8] c"data/similar.txt\00"
@.str.6 = [4 x i8] c"%d \00"
@.str.7 = [3 x i8] c"%f\00"
@.str.8 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca float
%5 = tail call i32* @malloc(i32 111080)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
%8 = bitcast float* %4 to i8*
br label %9
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %13, %9 ]
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = add nuw nsw i64 %10, 1
%14 = icmp eq i64 %13, 27770
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = tail call i32 @fclose(i32* %6)
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @feof(i32* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %15, %21
%22 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %5, i64 %24
%26 = load i32, i32* %25
%27 = sitofp i32 %26 to float
%28 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), float %27)
%29 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %5, i64 %31
%33 = load i32, i32* %32
%34 = sitofp i32 %33 to float
%35 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), float %34)
%36 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), float* %4)
%37 = load float, float* %4
%38 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), float %37)
%39 = call i32 @feof(i32* %18)
%40 = icmp eq i32 %39, 0
br i1 %40, label %21, label %41
41: ; preds = %21, %15
%42 = call i32 @fclose(i32* %17)
%43 = call i32 @fclose(i32* %18)
%44 = call i32 @free(i32* %5)
ret i32 0
}