#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int);
int /*<<< orphan*/ fread(float **, int, long long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(float **, int, long long, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *file = fopen("GoogleNews-vectors-negative300.bin", "rb");
  if (file == NULL) {
    printf("Cannot open GoogleNews-vectors-negative300.bin\n");
    return 1;
  }
  printf("float size: %d\n", sizeof(float));
  FILE *indices_file = fopen("word2vec_indices", "wt");
  FILE *vectors_file = fopen("word2vec_vectors", "wb");
  long long num_words, word_dim;
  fscanf(file, "%lld", &num_words);
  fscanf(file, "%lld", &word_dim);
  printf("Number of words: %lld\n", num_words);
  int i;
  char string_buffer[4096];
  float vector_buffer[word_dim];
  for (i = 0; i < num_words; i++) {
    fscanf(file, "%s%*c", string_buffer);
    fprintf(indices_file, "%s\t%d\n", string_buffer, i);
    fread(&vector_buffer, sizeof(float), word_dim, file);
    fwrite(&vector_buffer, sizeof(float), word_dim, vectors_file);
  }
  fclose(indices_file);
  fclose(vectors_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <main+0x4e>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1335 <main+0x1c5>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1059(%rbp)
mov    $0x4,%esi
call   1050 <printf@plt>
lea    0xe88(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rcx
mov    -0x1059(%rbp),%al
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    %rsi,-0x1068(%rbp)
lea    -0x28(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x1068(%rbp),%rsi
mov    -0x1059(%rbp),%al
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x1059(%rbp),%al
mov    -0x28(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x1048(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1058(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x1050(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1312 <main+0x1a2>
mov    -0x10(%rbp),%rdi
lea    -0x1040(%rbp),%rdx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1040(%rbp),%rdx
mov    -0x34(%rbp),%ecx
lea    0xde3(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x1058(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    -0x1058(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1090 <fwrite@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1291 <main+0x121>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x1048(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
lea    0xed5(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d5 <main+0x155>
mov    %rax,%r13
lea    0xe49(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe46(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
lea    0xe41(%rip),%rbx
lea    -0x38(%rbp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
lea    -0x30(%rbp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmpq   $0x0,-0x38(%rbp)
jle    12bc <main+0x13c>
lea    -0x1050(%rbp),%r14
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xded(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    -0x40(%rbp),%rdi
lea    0xdde(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r13,%rcx
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r12,%rcx
call   10a0 <fwrite@plt>
add    $0x1,%r15
cmp    %r15,-0x38(%rbp)
jg     1260 <main+0xe0>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rsp
xor    %eax,%eax
jmp    12e6 <main+0x166>
lea    0xd88(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"GoogleNews-vectors-negative300.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [48 x i8] c"Cannot open GoogleNews-vectors-negative300.bin\0A\00"
@.str.3 = [16 x i8] c"float size: %d\0A\00"
@.str.4 = [17 x i8] c"word2vec_indices\00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [17 x i8] c"word2vec_vectors\00"
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [5 x i8] c"%lld\00"
@.str.9 = [23 x i8] c"Number of words: %lld\0A\00"
@.str.10 = [6 x i8] c"%s%*c\00"
@.str.11 = [7 x i8] c"%s\09%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %59
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 4)
%18 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %18, i32** %3
%19 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %19, i32** %4
%20 = load i32*, i32** %2
%21 = call i32 (i32*, i8*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64* %5)
%22 = load i32*, i32** %2
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64* %6)
%24 = load i64, i64* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %6
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %9
%28 = alloca float, i64 %26
store i64 %26, i64* %10
store i32 0, i32* %7
br label %29
29: ; preds = %50, %16
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = load i64, i64* %5
%33 = icmp slt i64 %31, %32
br i1 %33, label %34, label %53
34: ; preds = %29
%35 = load i32*, i32** %2
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%37 = call i32 (i32*, i8*, ...) @fscanf(i32* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %36)
%38 = load i32*, i32** %3
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%40 = load i32, i32* %7
%41 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %39, i32 %40)
%42 = bitcast float* %28 to float**
%43 = load i64, i64* %6
%44 = load i32*, i32** %2
%45 = call i32 @fread(float** %42, i32 4, i64 %43, i32* %44)
%46 = bitcast float* %28 to float**
%47 = load i64, i64* %6
%48 = load i32*, i32** %4
%49 = call i32 @fwrite(float** %46, i32 4, i64 %47, i32* %48)
br label %50
50: ; preds = %34
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %29
53: ; preds = %29
%54 = load i32*, i32** %3
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %4
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %1
%58 = load i8*, i8** %9
br label %59
59: ; preds = %53, %14
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [35 x i8] c"GoogleNews-vectors-negative300.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [16 x i8] c"float size: %d\0A\00"
@.str.4 = [17 x i8] c"word2vec_indices\00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [17 x i8] c"word2vec_vectors\00"
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [5 x i8] c"%lld\00"
@.str.9 = [23 x i8] c"Number of words: %lld\0A\00"
@.str.10 = [6 x i8] c"%s%*c\00"
@.str.11 = [7 x i8] c"%s\09%d\0A\00"
@str = [47 x i8] c"Cannot open GoogleNews-vectors-negative300.bin\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [4096 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %41
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 4)
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%12 = bitcast i64* %1 to i8*
%13 = bitcast i64* %2 to i8*
%14 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64* %1)
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64* %2)
%16 = load i64, i64* %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 %16)
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%19 = load i64, i64* %2
%20 = call i8* @llvm.stacksave()
%21 = alloca float, i64 %19
%22 = load i64, i64* %1
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %8
%25 = bitcast float* %21 to float**
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %35, %26 ]
%28 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %18)
%29 = trunc i64 %27 to i32
%30 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %18, i32 %29)
%31 = load i64, i64* %2
%32 = call i32 @fread(float** %25, i32 4, i64 %31, i32* %4)
%33 = load i64, i64* %2
%34 = call i32 @fwrite(float** %25, i32 4, i64 %33, i32* %11)
%35 = add nuw nsw i64 %27, 1
%36 = load i64, i64* %1
%37 = icmp sgt i64 %36, %35
br i1 %37, label %26, label %38
38: ; preds = %26, %8
%39 = call i32 @fclose(i32* %10)
%40 = call i32 @fclose(i32* %11)
br label %41
41: ; preds = %38, %6
%42 = phi i32 [ 1, %6 ], [ 0, %38 ]
ret i32 %42
}