#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__ ftn2c_string_copy(unsigned char *, unsigned char *, int, int,
                             unsigned char);
int ftn2c_cstra_fstra(unsigned char **src, unsigned char *dest, int lsrc,
                      int ldest, int nitems, unsigned char pad) {
  int ii;
  if (nitems <= 0)
    return (-1);
  for (ii = 0; ii < nitems; ii++) {
    if (ftn2c_string_copy(src[ii], dest, lsrc, ldest, pad) < 0)
      return (-1);
    dest += ldest;
  }
  return (0);
}


x86 assembly (clang, -O0):
<ftn2c_cstra_fstra>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9b,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %al,-0x25(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     1146 <ftn2c_cstra_fstra+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <ftn2c_cstra_fstra+0xa5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ae <ftn2c_cstra_fstra+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
movzbl -0x25(%rbp),%r8d
call   1030 <ftn2c_string_copy@plt>
cmp    $0x0,%rax
jge    118f <ftn2c_cstra_fstra+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <ftn2c_cstra_fstra+0xa5>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114d <ftn2c_cstra_fstra+0x3d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftn2c_cstra_fstra>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %rdi,0x10(%rsp)
mov    $0xffffffff,%eax
test   %r8d,%r8d
jle    1185 <ftn2c_cstra_fstra+0x75>
mov    %ecx,%r13d
mov    %rsi,%rbx
movslq %ecx,%r14
mov    %r8d,%r15d
xor    %r12d,%r12d
movzbl %r9b,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
mov    %r13d,%ecx
mov    %ebp,%r8d
call   1030 <ftn2c_string_copy@plt>
test   %rax,%rax
js     1180 <ftn2c_cstra_fstra+0x70>
add    %r14,%rbx
add    $0x1,%r12
cmp    %r12,%r15
jne    1150 <ftn2c_cstra_fstra+0x40>
xor    %eax,%eax
jmp    1185 <ftn2c_cstra_fstra+0x75>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ftn2c_cstra_fstra(i8** nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4, i8 zeroext %5) {
%7 = icmp slt i32 %4, 1
br i1 %7, label %22, label %8
8: ; preds = %6
%9 = sext i32 %3 to i64
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %8, %18
%12 = phi i64 [ 0, %8 ], [ %20, %18 ]
%13 = phi i8* [ %1, %8 ], [ %19, %18 ]
%14 = getelementptr inbounds i8*, i8** %0, i64 %12
%15 = load i8*, i8** %14
%16 = tail call i64 @ftn2c_string_copy(i8* %15, i8* %13, i32 %2, i32 %3, i8 zeroext %5)
%17 = icmp slt i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %13, i64 %9
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %11, %18, %6
%23 = phi i32 [ -1, %6 ], [ -1, %11 ], [ 0, %18 ]
ret i32 %23
}