#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 */
char *calloc(size_t, int);
char *str_get_file(char const *);
char *str_get_path(char const *);
size_t str_last_index(char const *, char);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *append_c_out(const char *str) {
  char *a, *f, *p;
  size_t str_sz = strlen(str);
  if (!(a = calloc(str_sz + 2, sizeof(char)))) {
    return NULL;
  }
  size_t str_b_index = str_last_index(str, '/');
  if (!str_b_index) {
    strcpy(a, "c");
    strcat(a, str);
    return a;
  }
  const char *a_f = str_get_file(str);
  const char *a_p = str_get_path(str);
  if (!(f = calloc((str_sz - str_b_index) + 2, sizeof(char)))) {
    return NULL;
  }
  if (!(p = calloc(str_b_index + 1, sizeof(char)))) {
    return NULL;
  }
  strcpy(f, "c");
  strcat(f, a_f);
  strcpy(p, a_p);
  strcpy(a, p);
  strcat(a, "/");
  strcat(a, f);
  return a;
}


x86 assembly (clang, -O0):
<append_c_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b6 <append_c_out+0x46>
movq   $0x0,-0x8(%rbp)
jmp    12d1 <append_c_out+0x161>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <str_last_index@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11fd <append_c_out+0x8d>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d1 <append_c_out+0x161>
mov    -0x10(%rbp),%rdi
call   1070 <str_get_file@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <str_get_path@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
sub    -0x38(%rbp),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1248 <append_c_out+0xd8>
movq   $0x0,-0x8(%rbp)
jmp    12d1 <append_c_out+0x161>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1275 <append_c_out+0x105>
movq   $0x0,-0x8(%rbp)
jmp    12d1 <append_c_out+0x161>
mov    -0x20(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_c_out>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %rax,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1244 <append_c_out+0xd4>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x2f,%esi
call   1090 <str_last_index@plt>
test   %rax,%rax
je     1249 <append_c_out+0xd9>
mov    %rax,%rbp
mov    %r14,%rdi
call   1070 <str_get_file@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <str_get_path@plt>
mov    %rax,%r13
sub    %rbp,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1244 <append_c_out+0xd4>
mov    %rax,%r14
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1244 <append_c_out+0xd4>
mov    %rax,%rbx
lea    0xdf6(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xdc8(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
jmp    1258 <append_c_out+0xe8>
xor    %r15d,%r15d
jmp    1263 <append_c_out+0xf3>
lea    0xdb0(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"c\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @append_c_out(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = add i64 %13, 2
%15 = call i8* @calloc(i64 %14, i32 1)
store i8* %15, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
store i8* null, i8** %2
br label %66
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = call i64 @str_last_index(i8* %19, i8 signext 47)
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = icmp ne i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %4
store i8* %29, i8** %2
br label %66
30: ; preds = %18
%31 = load i8*, i8** %3
%32 = call i8* @str_get_file(i8* %31)
store i8* %32, i8** %9
%33 = load i8*, i8** %3
%34 = call i8* @str_get_path(i8* %33)
store i8* %34, i8** %10
%35 = load i64, i64* %7
%36 = load i64, i64* %8
%37 = sub i64 %35, %36
%38 = add i64 %37, 2
%39 = call i8* @calloc(i64 %38, i32 1)
store i8* %39, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %42, label %41
41: ; preds = %30
store i8* null, i8** %2
br label %66
42: ; preds = %30
%43 = load i64, i64* %8
%44 = add i64 %43, 1
%45 = call i8* @calloc(i64 %44, i32 1)
store i8* %45, i8** %6
%46 = icmp ne i8* %45, null
br i1 %46, label %48, label %47
47: ; preds = %42
store i8* null, i8** %2
br label %66
48: ; preds = %42
%49 = load i8*, i8** %5
%50 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%51 = load i8*, i8** %5
%52 = load i8*, i8** %9
%53 = call i32 @strcat(i8* %51, i8* %52)
%54 = load i8*, i8** %6
%55 = load i8*, i8** %10
%56 = call i32 @strcpy(i8* %54, i8* %55)
%57 = load i8*, i8** %4
%58 = load i8*, i8** %6
%59 = call i32 @strcpy(i8* %57, i8* %58)
%60 = load i8*, i8** %4
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%62 = load i8*, i8** %4
%63 = load i8*, i8** %5
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %4
store i8* %65, i8** %2
br label %66
66: ; preds = %48, %47, %41, %23, %17
%67 = load i8*, i8** %2
ret i8* %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"c\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @append_c_out(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 2
%4 = tail call i8* @calloc(i64 %3, i32 1)
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = tail call i64 @str_last_index(i8* %0, i8 signext 47)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strcat(i8* %4, i8* %0)
br label %29
12: ; preds = %6
%13 = tail call i8* @str_get_file(i8* %0)
%14 = tail call i8* @str_get_path(i8* %0)
%15 = sub i64 %3, %7
%16 = tail call i8* @calloc(i64 %15, i32 1)
%17 = icmp eq i8* %16, null
br i1 %17, label %29, label %18
18: ; preds = %12
%19 = add i64 %7, 1
%20 = tail call i8* @calloc(i64 %19, i32 1)
%21 = icmp eq i8* %20, null
br i1 %21, label %29, label %22
22: ; preds = %18
%23 = tail call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @strcat(i8* %16, i8* %13)
%25 = tail call i32 @strcpy(i8* %20, i8* %14)
%26 = tail call i32 @strcpy(i8* %4, i8* %20)
%27 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @strcat(i8* %4, i8* %16)
br label %29
29: ; preds = %9, %18, %12, %22, %1
%30 = phi i8* [ null, %1 ], [ %4, %9 ], [ %4, %22 ], [ null, %12 ], [ null, %18 ]
ret i8* %30
}