#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *maybe_colorize(char *color, char *str, bool really) {
  if (really) {
    char *new_str = malloc((10 + strlen(str)) * sizeof(char));
    sprintf(new_str, "%s%s", color, str);
    return new_str;
  }
  return str;
}


x86 assembly (clang, -O0):
<maybe_colorize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     118f <maybe_colorize+0x5f>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xa,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe83(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1197 <maybe_colorize+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maybe_colorize>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
test   %edx,%edx
je     116a <maybe_colorize+0x3a>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xa(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xea7(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <sprintf@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define i8* @maybe_colorize(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 10, %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i8*, i8** %8
store i8* %23, i8** %4
br label %26
24: ; preds = %3
%25 = load i8*, i8** %6
store i8* %25, i8** %4
br label %26
26: ; preds = %24, %11
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i8* @maybe_colorize(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 10
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %10
10: ; preds = %3, %5
%11 = phi i8* [ %8, %5 ], [ %1, %3 ]
ret i8* %11
}