#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, long *, long *, ...);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    return 1;
  }
  FILE *f;
  long cat, file_id, feat_id, feat_freq;
  char *line = NULL;
  int offset;
  size_t line_size = 0;
  ssize_t read_len;
  char *features, *feature;
  f = fopen(argv[1], "r");
  if (f == NULL)
    exit(EXIT_FAILURE);
  while ((read_len = getline(&line, &line_size, f)) != -1) {
    sscanf(line, "%ld 0:%ld%n", &cat, &file_id, &offset);
    printf("{\"_id\": %d, \"cat_id\": %d, \"features\": [", file_id, cat);
    features = line + offset;
    feature = strtok(features, " \n");
    while (1) {
      sscanf(feature, "%ld:%ld", &feat_id, &feat_freq);
      printf("{\"feat_id\": %d, \"freq\": %d}", feat_id, feat_freq);
      feature = strtok(NULL, " \n");
      if (feature == NULL)
        break;
      else
        printf(", ");
    }
    printf("]}\n");
  }
  free(line);
  fclose(f);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbp
ret
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1201 <main+0x81>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1206 <main+0x86>
mov    -0x18(%rbp),%rdx
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
je     12f4 <main+0x174>
mov    -0x40(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x44(%rbp),%r8
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rax
movslq -0x44(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xdc6(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd93(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    12ce <main+0x14e>
jmp    12e1 <main+0x161>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127a <main+0xfa>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1206 <main+0x86>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x2,%edi
je     11c8 <main+0x38>
mov    (%rsi),%rsi
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movq   $0x0,0x8(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x8(%rsi),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
jne    121c <main+0x8c>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     133c <main+0x1ac>
mov    0x8(%rsp),%rdi
lea    0xdcf(%rip),%rsi
lea    0x40(%rsp),%rdx
lea    0x38(%rsp),%rcx
lea    0x1c(%rsp),%r8
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    0x38(%rsp),%rsi
mov    0x40(%rsp),%rdx
lea    0xdb4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movslq 0x1c(%rsp),%rdi
add    0x8(%rsp),%rdi
lea    0xdc4(%rip),%r15
mov    %r15,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
lea    0xdb5(%rip),%rsi
lea    0x30(%rsp),%r13
mov    %r13,%rdx
lea    0x28(%rsp),%rbp
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    0x30(%rsp),%rsi
mov    0x28(%rsp),%rdx
lea    0xd95(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %r15,%rbx
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
lea    0xd90(%rip),%r12
je     1210 <main+0x80>
mov    %rax,%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
lea    0xd47(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    0x30(%rsp),%rsi
mov    0x28(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
jne    12f0 <main+0x160>
jmp    1210 <main+0x80>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"%ld 0:%ld%n\00"
@.str.3 = [40 x i8] c"{\22_id\22: %d, \22cat_id\22: %d, \22features\22: [\00"
@.str.4 = [3 x i8] c" \0A\00"
@.str.5 = [8 x i8] c"%ld:%ld\00"
@.str.6 = [28 x i8] c"{\22feat_id\22: %d, \22freq\22: %d}\00"
@.str.7 = [3 x i8] c", \00"
@.str.8 = [4 x i8] c"]}\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
ret i32 1
24: ; preds = %2
store i8* null, i8** %11
store i64 0, i64* %13
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %24
br label %35
35: ; preds = %64, %34
%36 = load i32*, i32** %6
%37 = call i32 @getline(i8** %11, i64* %13, i32* %36)
store i32 %37, i32* %14
%38 = icmp ne i32 %37, -1
br i1 %38, label %39, label %66
39: ; preds = %35
%40 = load i8*, i8** %11
%41 = call i32 (i8*, i8*, i64*, i64*, ...) @sscanf(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64* %7, i64* %8, i32* %12)
%42 = load i64, i64* %8
%43 = load i64, i64* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %42, i64 %43)
%45 = load i8*, i8** %11
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8* %48, i8** %15
%49 = load i8*, i8** %15
%50 = call i8* @strtok(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %50, i8** %16
br label %51
51: ; preds = %39, %63
%52 = load i8*, i8** %16
%53 = call i32 (i8*, i8*, i64*, i64*, ...) @sscanf(i8* %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64* %9, i64* %10)
%54 = load i64, i64* %9
%55 = load i64, i64* %10
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 %54, i64 %55)
%57 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %57, i8** %16
%58 = load i8*, i8** %16
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %61
60: ; preds = %51
br label %64
61: ; preds = %51
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %61
br label %51
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %35
66: ; preds = %35
%67 = load i8*, i8** %11
%68 = call i32 @free(i8* %67)
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* @EXIT_SUCCESS
%72 = call i32 @exit(i32 %71)
unreachable
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"%ld 0:%ld%n\00"
@.str.3 = [40 x i8] c"{\22_id\22: %d, \22cat_id\22: %d, \22features\22: [\00"
@.str.4 = [3 x i8] c" \0A\00"
@.str.5 = [8 x i8] c"%ld:%ld\00"
@.str.6 = [28 x i8] c"{\22feat_id\22: %d, \22freq\22: %d}\00"
@.str.7 = [3 x i8] c", \00"
@EXIT_SUCCESS = global i32 0
@str = [3 x i8] c"]}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = icmp eq i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
ret i32 1
14: ; preds = %2
%15 = bitcast i64* %3 to i8*
%16 = bitcast i64* %4 to i8*
%17 = bitcast i64* %5 to i8*
%18 = bitcast i64* %6 to i8*
%19 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%20 = bitcast i32* %8 to i8*
%21 = bitcast i64* %9 to i8*
store i64 0, i64* %9
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %14
%27 = call i32 @getline(i8** %7, i64* %9, i32* %24)
%28 = icmp eq i32 %27, -1
br i1 %28, label %62, label %32
29: ; preds = %14
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %26, %58
%33 = load i8*, i8** %7
%34 = call i32 (i8*, i8*, i64*, i64*, ...) @sscanf(i8* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4, i32* %8)
%35 = load i64, i64* %4
%36 = load i64, i64* %3
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %35, i64 %36)
%38 = load i8*, i8** %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i8* @strtok(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 (i8*, i8*, i64*, i64*, ...) @sscanf(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64* %5, i64* %6)
%44 = load i64, i64* %5
%45 = load i64, i64* %6
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 %44, i64 %45)
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %58, label %49
49: ; preds = %32, %49
%50 = phi i8* [ %56, %49 ], [ %47, %32 ]
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%52 = call i32 (i8*, i8*, i64*, i64*, ...) @sscanf(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64* %5, i64* %6)
%53 = load i64, i64* %5
%54 = load i64, i64* %6
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 %53, i64 %54)
%56 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %49
58: ; preds = %49, %32
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%60 = call i32 @getline(i8** %7, i64* %9, i32* %24)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %32
62: ; preds = %58, %26
%63 = load i8*, i8** %7
%64 = call i32 @free(i8* %63)
%65 = call i32 @fclose(i32* %24)
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}