#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;
long atol(char *);
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 *, ...);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s <cat_heir_file>\n", argv[0]);
    return 1;
  }
  FILE *f;
  long cat_heir[5];
  int i, heir_ht;
  char *line = NULL;
  size_t line_size = 0;
  ssize_t read_len;
  char *cat;
  f = fopen(argv[1], "r");
  if (f == NULL)
    exit(EXIT_FAILURE);
  while ((read_len = getline(&line, &line_size, f)) != -1) {
    heir_ht = 0;
    cat = strtok(line, " \n");
    while (cat != NULL) {
      cat_heir[heir_ht++] = atol(cat);
      cat = strtok(NULL, " \n");
    }
    printf("{\"dfs\": [%d", cat_heir[0]);
    for (i = 1; i < heir_ht; i++)
      printf(", %d", cat_heir[i]);
    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,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%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    -0x50(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0xffffffff,%eax
je     12dd <main+0x15d>
movl   $0x0,-0x48(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1280 <main+0x100>
mov    -0x68(%rbp),%rdi
call   1060 <atol@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x48(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdab(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x68(%rbp)
jmp    123e <main+0xbe>
mov    -0x40(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    12ca <main+0x14a>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1299 <main+0x119>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1206 <main+0x86>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ce2(%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,0x18(%rsp)
mov    0x8(%rsi),%rdi
lea    0xe36(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
jne    1202 <main+0x72>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
jne    123e <main+0xae>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xdd8(%rip),%r14
lea    0xde0(%rip),%r15
jmp    1282 <main+0xf2>
lea    0xdcb(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdcb(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     121e <main+0x8e>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     124e <main+0xbe>
mov    $0x1,%ecx
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %ecx,%ebp
mov    %rax,%rdi
call   1070 <atol@plt>
mov    %rax,0x20(%rsp,%r13,8)
add    $0x1,%r13
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <strtok@plt>
lea    0x1(%rbp),%ecx
test   %rax,%rax
jne    12a0 <main+0x110>
mov    0x20(%rsp),%r12
lea    0xd4f(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0xfffffffe,%r13d
je     125f <main+0xcf>
mov    %ebp,%ebp
mov    $0x1,%ebx
nop
mov    0x20(%rsp,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12f0 <main+0x160>
mov    0x10(%rsp),%rbx
jmp    125f <main+0xcf>

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

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