#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ stderr;
char *makeCString(const char *fortranString, const int fortranStringLength) {
  int iEnd;
  int cStringLength = -1;
  char *cString = NULL;
  if (fortranString != NULL) {
    for (iEnd = fortranStringLength - 1; iEnd >= 0; iEnd--) {
      if (fortranString[iEnd] != ' ') {
        break;
      }
    }
    cStringLength = iEnd + 1;
    cString = (char *)malloc(sizeof(char) * (cStringLength + 1));
    if (!cString) {
      fprintf(stderr, "Fatal error: Failed to allocate memory in makeCstring");
      abort();
    }
    memcpy(cString, fortranString, cStringLength * sizeof(char));
    cString[cStringLength] = '\0';
  }
  return cString;
}


x86 assembly (clang, -O0):
<makeCString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1213 <makeCString+0xd3>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11a9 <makeCString+0x69>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1196 <makeCString+0x56>
jmp    11a9 <makeCString+0x69>
jmp    119b <makeCString+0x5b>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <makeCString+0x32>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f0 <makeCString+0xb0>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeCString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     11a2 <makeCString+0x62>
mov    %rdi,%rbx
mov    %esi,%eax
test   %esi,%esi
cmovs  %esi,%r14d
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
jle    1178 <makeCString+0x38>
lea    -0x1(%rax),%rcx
cmpb   $0x20,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
je     1160 <makeCString+0x20>
add    $0x1,%ecx
mov    %ecx,%r14d
lea    0x1(%r14),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b1 <makeCString+0x71>
mov    %rax,%r15
movslq %r14d,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"Fatal error: Failed to allocate memory in makeCstring\00"
define i8* @makeCString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %6
store i8* null, i8** %7
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %57
10: ; preds = %2
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %5
br label %13
13: ; preds = %26, %10
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 32
br i1 %23, label %24, label %25
24: ; preds = %16
br label %29
25: ; preds = %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, -1
store i32 %28, i32* %5
br label %13
29: ; preds = %24, %13
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %45, label %41
41: ; preds = %29
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %29
%46 = load i8*, i8** %7
%47 = load i8*, i8** %3
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 1
%51 = trunc i64 %50 to i32
%52 = call i32 @memcpy(i8* %46, i8* %47, i32 %51)
%53 = load i8*, i8** %7
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %45, %2
%58 = load i8*, i8** %7
ret i8* %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"Fatal error: Failed to allocate memory in makeCstring\00"
define i8* @makeCString(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %32, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = call i32 @llvm.smin.i32(i32 %1, i32 0)
br label %7
7: ; preds = %4, %12
%8 = phi i64 [ %5, %4 ], [ %9, %12 ]
%9 = add nsw i64 %8, -1
%10 = trunc i64 %8 to i32
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 32
br i1 %15, label %7, label %16
16: ; preds = %12
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %7, %16
%19 = phi i32 [ %17, %16 ], [ %6, %7 ]
%20 = add nsw i32 %19, 1
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 (...) @abort()
unreachable
28: ; preds = %18
%29 = sext i32 %19 to i64
%30 = tail call i32 @memcpy(i8* %22, i8* %0, i32 %19)
%31 = getelementptr inbounds i8, i8* %22, i64 %29
store i8 0, i8* %31
br label %32
32: ; preds = %28, %2
%33 = phi i8* [ %22, %28 ], [ null, %2 ]
ret i8* %33
}