#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__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int CTA_cstr2fstr(char *c_str, char *f_str, int len_f) {
  int len_cpy;
  int i;
  len_cpy = ((int)strlen(c_str) < len_f ? (int)strlen(c_str) : len_f);
  strncpy(f_str, c_str, len_cpy);
  for (i = len_cpy; i < len_f; i++) {
    f_str[i] = ' ';
  }
  return (0);
}


x86 assembly (clang, -O0):
<CTA_cstr2fstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jge    1156 <CTA_cstr2fstr+0x36>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
jmp    115c <CTA_cstr2fstr+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119e <CTA_cstr2fstr+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <CTA_cstr2fstr+0x58>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CTA_cstr2fstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbp
cmp    %r12d,%ebp
mov    %r12d,%ebx
cmovl  %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
cmp    %r12d,%ebp
jge    1183 <CTA_cstr2fstr+0x53>
movslq %ebx,%rax
add    %rax,%r14
not    %ebx
add    %r12d,%ebx
add    $0x1,%rbx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CTA_cstr2fstr(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = trunc i64 %16 to i32
br label %20
18: ; preds = %3
%19 = load i32, i32* %6
br label %20
20: ; preds = %18, %14
%21 = phi i32 [ %17, %14 ], [ %19, %18 ]
store i32 %21, i32* %7
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = call i32 @strncpy(i8* %22, i8* %23, i32 %24)
%26 = load i32, i32* %7
store i32 %26, i32* %8
br label %27
27: ; preds = %36, %20
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 32, i8* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %27
39: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
define i32 @CTA_cstr2fstr(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = icmp slt i32 %5, %2
%7 = select i1 %6, i32 %5, i32 %2
%8 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %7)
br i1 %6, label %9, label %16
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = getelementptr i8, i8* %1, i64 %10
%12 = xor i32 %7, -1
%13 = add i32 %12, %2
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
br label %16
16: ; preds = %9, %3
ret i32 0
}