#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*/ memcpy(char *, char *, int);
int strlen(char *);
int generate_chars(char *out_str, int gen_len) {
  int total_count = gen_len;
  int cpy_len = 0;
  int input_chars_len = strlen("adsfsdfsadfsdfsa");
  while (total_count > 0) {
    if (total_count > input_chars_len) {
      memcpy(out_str + cpy_len, "adsfsdfsadfsdfsa", input_chars_len);
      total_count -= input_chars_len;
      cpy_len += input_chars_len;
    } else {
      memcpy(out_str + cpy_len, "adsfsdfsadfsdfsa", total_count);
      cpy_len += total_count;
      total_count -= total_count;
    }
  }
  if (gen_len != cpy_len) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<generate_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11c7 <generate_chars+0xa7>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1194 <generate_chars+0x74>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <generate_chars+0xa2>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <generate_chars+0x2b>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11df <generate_chars+0xbf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <generate_chars+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_chars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xec8(%rip),%rdi
call   1030 <strlen@plt>
test   %r14d,%r14d
jle    1189 <generate_chars+0x69>
mov    %eax,%r12d
movslq %eax,%r13
xor    %ebp,%ebp
lea    0xeaf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%edx
cmp    %r12d,%edx
jle    118d <generate_chars+0x6d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
sub    %r12d,%ebp
add    %r13,%rbx
lea    (%r14,%rbp,1),%eax
test   %eax,%eax
jg     1160 <generate_chars+0x40>
neg    %ebp
jmp    119f <generate_chars+0x7f>
xor    %ebp,%ebp
jmp    119f <generate_chars+0x7f>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <memcpy@plt>
mov    %r14d,%ebp
xor    %eax,%eax
cmp    %r14d,%ebp
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"adsfsdfsadfsdfsa\00"
define i32 @generate_chars(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
store i32 %9, i32* %6
store i32 0, i32* %7
%10 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %8
br label %11
11: ; preds = %44, %2
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %8
%24 = call i32 @memcpy(i8* %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, %25
store i32 %27, i32* %6
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, %28
store i32 %30, i32* %7
br label %44
31: ; preds = %14
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %6
%37 = call i32 @memcpy(i8* %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, %38
store i32 %40, i32* %7
%41 = load i32, i32* %6
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, %41
store i32 %43, i32* %6
br label %44
44: ; preds = %31, %18
br label %11
45: ; preds = %11
%46 = load i32, i32* %5
%47 = load i32, i32* %7
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 -1, i32* %3
br label %51
50: ; preds = %45
store i32 0, i32* %3
br label %51
51: ; preds = %50, %49
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [17 x i8] c"adsfsdfsadfsdfsa\00"
define i32 @generate_chars(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %19
5: ; preds = %2, %14
%6 = phi i32 [ %17, %14 ], [ 0, %2 ]
%7 = phi i32 [ %16, %14 ], [ %1, %2 ]
%8 = icmp sgt i32 %7, %3
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
br i1 %8, label %14, label %11
11: ; preds = %5
%12 = tail call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%13 = add nsw i32 %7, %6
br label %19
14: ; preds = %5
%15 = tail call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%16 = sub nsw i32 %7, %3
%17 = add nsw i32 %3, %6
%18 = icmp sgt i32 %16, 0
br i1 %18, label %5, label %19
19: ; preds = %14, %11, %2
%20 = phi i32 [ 0, %2 ], [ %13, %11 ], [ %17, %14 ]
%21 = icmp ne i32 %20, %1
%22 = sext i1 %21 to i32
ret i32 %22
}