#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 fscanf(int /*<<< orphan*/ *, char *, int *);
void get_input(int *const str1, int *const str1_length, int *const str2,
               int *const str2_length) {
  FILE *instream;
  int *curr_str;
  int *curr_str_length;
  int node_num;
  instream = fopen("/dev/stdin", "r");
  curr_str = str1;
  curr_str_length = str1_length;
  *curr_str_length = 0;
  while (fscanf(instream, "%d", &node_num) != -1) {
    if (node_num == -1) {
      curr_str = str2;
      curr_str_length = str2_length;
      *curr_str_length = 0;
      continue;
    }
    curr_str[*curr_str_length] = node_num;
    (*curr_str_length)++;
  }
  fclose(instream);
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    0xeb1(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0x3c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0xffffffff,%eax
je     11e0 <get_input+0xb0>
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11bf <get_input+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
jmp    1179 <get_input+0x49>
mov    -0x3c(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1179 <get_input+0x49>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,0x10(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xead(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
movl   $0x0,(%rbx)
lea    0xe9e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0xffffffff,%eax
je     11db <get_input+0xab>
lea    0xe85(%rip),%rbp
lea    0xc(%rsp),%r14
nopl   (%rax)
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     11b9 <get_input+0x89>
movslq (%rbx),%rcx
mov    %eax,0x0(%r13,%rcx,4)
addl   $0x1,(%rbx)
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    1190 <get_input+0x60>
jmp    11db <get_input+0xab>
movl   $0x0,(%r15)
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %r15,%rbx
mov    0x10(%rsp),%r13
cmp    $0xffffffff,%eax
jne    1190 <get_input+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/stdin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define void @get_input(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%13 = 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* %13, i32** %9
%14 = load i32*, i32** %5
store i32* %14, i32** %10
%15 = load i32*, i32** %6
store i32* %15, i32** %11
%16 = load i32*, i32** %11
store i32 0, i32* %16
br label %17
17: ; preds = %28, %24, %4
%18 = load i32*, i32** %9
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i32, i32* %12
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32*, i32** %7
store i32* %25, i32** %10
%26 = load i32*, i32** %8
store i32* %26, i32** %11
%27 = load i32*, i32** %11
store i32 0, i32* %27
br label %17
28: ; preds = %21
%29 = load i32, i32* %12
%30 = load i32*, i32** %10
%31 = load i32*, i32** %11
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
store i32 %29, i32* %34
%35 = load i32*, i32** %11
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %17
38: ; preds = %17
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/stdin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define void @get_input(i32* nocapture writeonly %0, i32* nocapture %1, i32* nocapture writeonly %2, i32* nocapture %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = 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))
store i32 0, i32* %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%9 = icmp eq i32 %8, -1
br i1 %9, label %27, label %10
10: ; preds = %4, %16
%11 = phi i32* [ %3, %16 ], [ %1, %4 ]
%12 = phi i32* [ %2, %16 ], [ %0, %4 ]
br label %13
13: ; preds = %10, %19
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
store i32 0, i32* %3
%17 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%18 = icmp eq i32 %17, -1
br i1 %18, label %27, label %10
19: ; preds = %13
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %12, i64 %21
store i32 %14, i32* %22
%23 = load i32, i32* %11
%24 = add nsw i32 %23, 1
store i32 %24, i32* %11
%25 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %13
27: ; preds = %16, %19, %4
%28 = call i32 @fclose(i32* %7)
ret void
}