#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int filereads(char *rstr, char *datastr, int *current, int end) {
  int a;
  a = *current;
  sscanf(datastr + a, "%s", rstr);
  printf("\'%s\'\n", rstr);
  a++;
  while (datastr[a] != 0) {
    a++;
    if (a >= end)
      return -1;
  }
  a++;
  *current = a;
  return 0;
}


x86 assembly (clang, -O0):
<filereads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11af <filereads+0x8f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     11aa <filereads+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <filereads+0xa8>
jmp    1174 <filereads+0x54>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filereads>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
movslq (%rdx),%rbp
mov    %rbp,%rdi
add    %rsi,%rdi
lea    0xebc(%rip),%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
lea    0xeb0(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
lea    0x1(%rbp),%eax
cltq
movslq %r15d,%rcx
lea    0x2(%rbp),%edx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx,%rax,1)
je     1189 <filereads+0x69>
add    $0x1,%rax
add    $0x1,%edx
cmp    %rcx,%rax
jl     1170 <filereads+0x50>
mov    $0xffffffff,%eax
jmp    118e <filereads+0x6e>
mov    %edx,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"'%s'\0A\00"
define i32 @filereads(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%11 = load i32*, i32** %8
%12 = load i32, i32* %11
store i32 %12, i32* %10
%13 = load i8*, i8** %7
%14 = load i32, i32* %10
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %6
%18 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
br label %23
23: ; preds = %38, %4
%24 = load i8*, i8** %7
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %23
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = load i32, i32* %9
%36 = icmp sge i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -1, i32* %5
br label %44
38: ; preds = %31
br label %23
39: ; preds = %23
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = load i32*, i32** %8
store i32 %42, i32* %43
store i32 0, i32* %5
br label %44
44: ; preds = %39, %37
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"'%s'\0A\00"
define i32 @filereads(i8* %0, i8* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = tail call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = add i32 %5, 1
%11 = sext i32 %10 to i64
%12 = sext i32 %3 to i64
br label %13
13: ; preds = %18, %4
%14 = phi i64 [ %19, %18 ], [ %11, %4 ]
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = add nsw i64 %14, 1
%20 = icmp slt i64 %19, %12
br i1 %20, label %13, label %24
21: ; preds = %13
%22 = trunc i64 %14 to i32
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %24
24: ; preds = %18, %21
%25 = phi i32 [ 0, %21 ], [ -1, %18 ]
ret i32 %25
}