#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 FILENAME_MAX;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mcfioC_InfoStreamChar(int, int, char *, int *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void mcfio_infostreamchar_(int *stream, int *key, char *answer, int *lret,
                           int length) {
  char *aString;
  int ll1;
  aString = (char *)malloc((FILENAME_MAX + 1) * sizeof(char));
  mcfioC_InfoStreamChar(*stream, *key, aString, lret);
  ll1 = *lret;
  if (ll1 > length)
    ll1 = length;
  strncpy(answer, aString, ll1);
  free(aString);
}


x86 assembly (clang, -O0):
<mcfio_infostreamchar_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <mcfioC_InfoStreamChar@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11ad <mcfio_infostreamchar_+0x6d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcfio_infostreamchar_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    (%r12),%edi
mov    (%r15),%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1050 <mcfioC_InfoStreamChar@plt>
mov    (%rbx),%edx
cmp    %r13d,%edx
cmovg  %r13d,%edx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strncpy@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
define void @mcfio_infostreamchar_(i32* %0, i32* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%13 = load i32, i32* @FILENAME_MAX
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %11
%20 = load i32*, i32** %6
%21 = load i32, i32* %20
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = load i8*, i8** %11
%25 = load i32*, i32** %9
%26 = call i32 @mcfioC_InfoStreamChar(i32 %21, i32 %23, i8* %24, i32* %25)
%27 = load i32*, i32** %9
%28 = load i32, i32* %27
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = load i32, i32* %10
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %5
%33 = load i32, i32* %10
store i32 %33, i32* %12
br label %34
34: ; preds = %32, %5
%35 = load i8*, i8** %8
%36 = load i8*, i8** %11
%37 = load i32, i32* %12
%38 = call i32 @strncpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %11
%40 = call i32 @free(i8* %39)
ret void
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
define void @mcfio_infostreamchar_(i32* nocapture %0, i32* nocapture %1, i8* %2, i32* %3, i32 %4) {
%6 = load i32, i32* @FILENAME_MAX
%7 = add nsw i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = load i32, i32* %0
%11 = load i32, i32* %1
%12 = tail call i32 @mcfioC_InfoStreamChar(i32 %10, i32 %11, i8* %9, i32* %3)
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, %4
%15 = select i1 %14, i32 %4, i32 %13
%16 = tail call i32 @strncpy(i8* %2, i8* %9, i32 %15)
%17 = tail call i32 @free(i8* %9)
ret void
}