#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*/ enough_mem(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
char *strdup(char const *);
int strlen(char const *);
char *char_prepend(const char *prefix, const char *ostr) {
  char *nstr;
  int newsize;
  if (!ostr && !prefix) {
    return (char *)0;
  }
  if (!ostr) {
    return strdup(prefix);
  }
  if (!prefix) {
    return strdup(ostr);
  }
  newsize = strlen(ostr) + strlen(prefix) + 1;
  nstr = (char *)malloc(newsize);
  enough_mem(nstr);
  snprintf(nstr, newsize, "%s%s", prefix, ostr);
  return nstr;
}


x86 assembly (clang, -O0):
<char_prepend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <char_prepend+0x33>
cmpq   $0x0,-0x10(%rbp)
jne    1183 <char_prepend+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1217 <char_prepend+0xc7>
cmpq   $0x0,-0x18(%rbp)
jne    11a0 <char_prepend+0x50>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1217 <char_prepend+0xc7>
cmpq   $0x0,-0x10(%rbp)
jne    11bd <char_prepend+0x6d>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1217 <char_prepend+0xc7>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <enough_mem@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdf6(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_prepend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rax
or     %rsi,%rax
je     11b4 <char_prepend+0x64>
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     11c5 <char_prepend+0x75>
test   %r14,%r14
je     11ca <char_prepend+0x7a>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <enough_mem@plt>
lea    0xe5e(%rip),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1040 <snprintf@plt>
jmp    11b7 <char_prepend+0x67>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    11cd <char_prepend+0x7d>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <strdup@plt>

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

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