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


x86 assembly (clang, -O0):
<mcfio_infoblockchar_>:
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    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <mcfioC_InfoBlockChar@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    11b7 <mcfio_infoblockchar_+0x77>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcfio_infoblockchar_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r13d
mov    %r8,%rbx
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x0(%rbp),%edi
mov    (%r12),%esi
mov    (%r15),%edx
mov    %rax,%rcx
mov    %rbx,%r8
call   1060 <mcfioC_InfoBlockChar@plt>
mov    (%rbx),%edx
cmp    %r13d,%edx
cmovg  %r13d,%edx
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
mov    %r14,%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_infoblockchar_(i32* %0, i32* %1, i32* %2, i8* %3, i32* %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i32 %5, i32* %12
%15 = load i32, i32* @FILENAME_MAX
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %13
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = load i32*, i32** %8
%25 = load i32, i32* %24
%26 = load i32*, i32** %9
%27 = load i32, i32* %26
%28 = load i8*, i8** %13
%29 = load i32*, i32** %11
%30 = call i32 @mcfioC_InfoBlockChar(i32 %23, i32 %25, i32 %27, i8* %28, i32* %29)
%31 = load i32*, i32** %11
%32 = load i32, i32* %31
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = load i32, i32* %12
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %6
%37 = load i32, i32* %12
store i32 %37, i32* %14
br label %38
38: ; preds = %36, %6
%39 = load i8*, i8** %10
%40 = load i8*, i8** %13
%41 = load i32, i32* %14
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
%43 = load i8*, i8** %13
%44 = call i32 @free(i8* %43)
ret void
}

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