#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ReadFortranString(char *line, int istart, int ilen, char *string_in) {
  char chrtmp[101], *chrpos;
  chrpos = strchr(line, '\0');
  if (chrpos - line < istart + ilen - 1)
    return (-1);
  strncpy(chrtmp, line + (istart - 1), ilen);
  chrtmp[ilen] = '\0';
  strncpy(string_in, chrtmp, ilen);
  string_in[ilen] = '\0';
  return (1);
}


x86 assembly (clang, -O0):
<ReadFortranString>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    117a <ReadFortranString+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <ReadFortranString+0xaa>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFortranString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rcx
lea    (%rbx,%r15,1),%eax
add    $0xffffffff,%eax
movslq %eax,%rdx
mov    $0xffffffff,%eax
cmp    %rdx,%rcx
jl     118d <ReadFortranString+0x6d>
add    $0xffffffff,%ebx
movslq %ebx,%rax
add    %rax,%r12
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rbx
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ReadFortranString(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [101 x i8]
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i8*, i8** %6
%13 = call i8* @strchr(i8* %12, i8 signext 0)
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = load i8*, i8** %6
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = add nsw i32 %19, %20
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %18, %23
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 -1, i32* %5
br label %46
26: ; preds = %4
%27 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i32, i32* %8
%34 = call i32 @strncpy(i8* %27, i8* %32, i32 %33)
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %9
%39 = getelementptr inbounds [101 x i8], [101 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @strncpy(i8* %38, i8* %39, i32 %40)
%42 = load i8*, i8** %9
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
store i32 1, i32* %5
br label %46
46: ; preds = %26, %25
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @ReadFortranString(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [101 x i8]
%6 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add i32 %1, -1
%9 = add i32 %8, %2
%10 = sext i32 %9 to i64
%11 = icmp slt i64 %7, %10
br i1 %11, label %20, label %12
12: ; preds = %4
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = call i32 @strncpy(i8* %6, i8* %14, i32 %2)
%16 = sext i32 %2 to i64
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @strncpy(i8* %3, i8* %6, i32 %2)
%19 = getelementptr inbounds i8, i8* %3, i64 %16
store i8 0, i8* %19
br label %20
20: ; preds = %4, %12
%21 = phi i32 [ 1, %12 ], [ -1, %4 ]
ret i32 %21
}