#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 outer_fn(char *out_var, int out_var_len, char *arg_0, int arg_0_len) {
  int part1_len = (((strlen("inner_")) < (out_var_len)) ? (strlen("inner_"))
                                                        : (out_var_len));
  memcpy(out_var, "outer_", part1_len);
  int part2_len =
      (((arg_0_len) < (out_var_len - part1_len)) ? (arg_0_len)
                                                 : (out_var_len - part1_len));
  memcpy(out_var + part1_len, arg_0, part2_len);
  return part2_len + part1_len;
}


x86 assembly (clang, -O0):
<outer_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <strlen@plt>
cmp    -0xc(%rbp),%eax
jge    115f <outer_fn+0x3f>
lea    0xeae(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
jmp    1165 <outer_fn+0x45>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe8e(%rip),%rsi
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    119a <outer_fn+0x7a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11a3 <outer_fn+0x83>
mov    -0xc(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outer_fn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xec6(%rip),%rdi
call   1030 <strlen@plt>
mov    %ebx,%ebp
cmp    %ebx,%eax
jge    1153 <outer_fn+0x33>
lea    0xeb4(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xead(%rip),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
sub    %ebp,%ebx
cmp    %r12d,%ebx
cmovg  %r12d,%ebx
movslq %ebp,%rbp
add    %rbp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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