#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *string_f90_to_c(char *fortchar) {
  char *name = fortchar;
  int len = 256;
  char *newp = (char *)malloc(len + 1);
  if (!newp) {
    perror("malloc problem in string_f90_to_c");
    return ((char *)0);
  }
  len = 256;
  strncpy(newp, name, len);
  newp[len] = '\0';
  len = 255;
  while ((len > 0) && ((newp[len] == ' ') || (newp[len] == '\0'))) {
    len--;
  }
  newp[++len] = '\0';
  return (newp);
}


x86 assembly (clang, -O0):
<string_f90_to_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x100,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117e <string_f90_to_c+0x4e>
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <string_f90_to_c+0xf6>
movl   $0x100,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0xff,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jle    11ec <string_f90_to_c+0xbc>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x2a(%rbp)
je     11e6 <string_f90_to_c+0xb6>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11fc <string_f90_to_c+0xcc>
jmp    120a <string_f90_to_c+0xda>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <string_f90_to_c+0x78>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_f90_to_c>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x101,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11cd <string_f90_to_c+0x9d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x100(%rbx)
mov    $0xfb,%eax
nopl   0x0(%rax)
testb  $0xdf,0x4(%rbx,%rax,1)
jne    11a3 <string_f90_to_c+0x73>
testb  $0xdf,0x3(%rbx,%rax,1)
jne    11a9 <string_f90_to_c+0x79>
testb  $0xdf,0x2(%rbx,%rax,1)
jne    11af <string_f90_to_c+0x7f>
testb  $0xdf,0x1(%rbx,%rax,1)
jne    11b5 <string_f90_to_c+0x85>
testb  $0xdf,(%rbx,%rax,1)
jne    11b9 <string_f90_to_c+0x89>
lea    -0x5(%rax),%rcx
cmp    $0x1,%rax
mov    %rcx,%rax
ja     1170 <string_f90_to_c+0x40>
xor    %eax,%eax
jmp    11b9 <string_f90_to_c+0x89>
add    $0x4,%rax
jmp    11b9 <string_f90_to_c+0x89>
add    $0x3,%rax
jmp    11b9 <string_f90_to_c+0x89>
add    $0x2,%rax
jmp    11b9 <string_f90_to_c+0x89>
add    $0x1,%rax
add    $0x1,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2c(%rip),%rdi
call   1050 <perror@plt>
xor    %ebx,%ebx
jmp    11c2 <string_f90_to_c+0x92>

LLVM IR (-O0):
@.str = [34 x i8] c"malloc problem in string_f90_to_c\00"
define i8* @string_f90_to_c(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
store i32 256, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 1
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %58
16: ; preds = %1
store i32 256, i32* %5
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i32 @strncpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %6
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
store i32 255, i32* %5
br label %25
25: ; preds = %48, %16
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 32
br i1 %35, label %44, label %36
36: ; preds = %28
%37 = load i8*, i8** %6
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br label %44
44: ; preds = %36, %28
%45 = phi i1 [ true, %28 ], [ %43, %36 ]
br label %46
46: ; preds = %44, %25
%47 = phi i1 [ false, %25 ], [ %45, %44 ]
br i1 %47, label %48, label %51
48: ; preds = %46
%49 = load i32, i32* %5
%50 = add nsw i32 %49, -1
store i32 %50, i32* %5
br label %25
51: ; preds = %46
%52 = load i8*, i8** %6
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %6
store i8* %57, i8** %2
br label %58
58: ; preds = %51, %14
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@.str = [34 x i8] c"malloc problem in string_f90_to_c\00"
define i8* @string_f90_to_c(i8* %0) {
%2 = tail call i64 @malloc(i32 257)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %39
7: ; preds = %1
%8 = tail call i32 @strncpy(i8* %3, i8* %0, i32 256)
%9 = getelementptr inbounds i8, i8* %3, i64 256
store i8 0, i8* %9
br label %10
10: ; preds = %30, %7
%11 = phi i64 [ 255, %7 ], [ %31, %30 ]
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %33 [
i8 32, label %14
i8 0, label %14
]
14: ; preds = %10, %10
%15 = add nsw i64 %11, -1
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = load i8, i8* %16
switch i8 %17, label %33 [
i8 32, label %18
i8 0, label %18
]
18: ; preds = %14, %14
%19 = add nsw i64 %11, -2
%20 = getelementptr inbounds i8, i8* %3, i64 %19
%21 = load i8, i8* %20
switch i8 %21, label %33 [
i8 32, label %22
i8 0, label %22
]
22: ; preds = %18, %18
%23 = add nsw i64 %11, -3
%24 = getelementptr inbounds i8, i8* %3, i64 %23
%25 = load i8, i8* %24
switch i8 %25, label %33 [
i8 32, label %26
i8 0, label %26
]
26: ; preds = %22, %22
%27 = add nsw i64 %11, -4
%28 = getelementptr inbounds i8, i8* %3, i64 %27
%29 = load i8, i8* %28
switch i8 %29, label %33 [
i8 32, label %30
i8 0, label %30
]
30: ; preds = %26, %26
%31 = add nsw i64 %11, -5
%32 = icmp ugt i64 %27, 1
br i1 %32, label %10, label %33
33: ; preds = %30, %26, %22, %18, %14, %10
%34 = phi i64 [ %11, %10 ], [ %15, %14 ], [ %19, %18 ], [ %23, %22 ], [ %27, %26 ], [ 0, %30 ]
%35 = shl i64 %34, 32
%36 = add i64 %35, 4294967296
%37 = ashr exact i64 %36, 32
%38 = getelementptr inbounds i8, i8* %3, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %33, %5
%40 = phi i8* [ %3, %33 ], [ null, %5 ]
ret i8* %40
}