#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*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *strncpy(char *, char *, int);
char *mcf_ValidStr(char *string, int max_length, char *strKind) {
  static char str[255 + 1];
  static char str1[1] = "";
  if (string == NULL)
    return str1;
  if (strlen(string) <= max_length)
    return string;
  fprintf(stderr,
          "Mcfio_Ntuple: Error. Specified %s string is too long, truncating\n  "
          "   ->%s\n",
          strKind, string);
  memset(str, 0, 255 + 1);
  return strncpy(str, string, max_length);
}


x86 assembly (clang, -O0):
<mcf_ValidStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <mcf_ValidStr+0x2e>
lea    0x2feb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <mcf_ValidStr+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jg     118d <mcf_ValidStr+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <mcf_ValidStr+0x94>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe5b(%rip),%rsi
call   1060 <fprintf@plt>
lea    0x2e9f(%rip),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0x2e85(%rip),%rdi
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcf_ValidStr>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     119c <mcf_ValidStr+0x5c>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %ebp,%eax
jle    11a3 <mcf_ValidStr+0x63>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
lea    0x2ed4(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strncpy@plt>
lea    0x2fad(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@mcf_ValidStr.str = internal global [256 x i8] zeroinitializer
@mcf_ValidStr.str1 = internal global [1 x i8] zeroinitializer
@stderr = global i32 0
@.str = [76 x i8] c"Mcfio_Ntuple: Error. Specified %s string is too long, truncating\0A ->%s\0A\00"
define i8* @mcf_ValidStr(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @mcf_ValidStr.str1, i64 0, i64 0), i8** %4
br label %27
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %5
store i8* %17, i8** %4
br label %27
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %7
%21 = load i8*, i8** %5
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
%23 = call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mcf_ValidStr.str, i64 0, i64 0), i32 0, i32 256)
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = call i8* @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mcf_ValidStr.str, i64 0, i64 0), i8* %24, i32 %25)
store i8* %26, i8** %4
br label %27
27: ; preds = %18, %16, %10
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
@mcf_ValidStr.str = internal global [256 x i8] zeroinitializer
@mcf_ValidStr.str1 = internal global [1 x i8] zeroinitializer
@stderr = global i32 0
@.str = [76 x i8] c"Mcfio_Ntuple: Error. Specified %s string is too long, truncating\0A ->%s\0A\00"
define i8* @mcf_ValidStr(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, %1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
%11 = tail call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mcf_ValidStr.str, i64 0, i64 0), i32 0, i32 256)
%12 = tail call i8* @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mcf_ValidStr.str, i64 0, i64 0), i8* %0, i32 %1)
br label %13
13: ; preds = %5, %3, %8
%14 = phi i8* [ %12, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @mcf_ValidStr.str1, i64 0, i64 0), %3 ], [ %0, %5 ]
ret i8* %14
}