#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*/ CUTIL_GenerateRandomString(char *, size_t);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *CUTIL_GenerateRandomStringWithPrefix(const char *prefix, char *buf,
                                           size_t size) {
  if (prefix) {
    size_t length = strlen(prefix);
    if (length > size) {
      return NULL;
    }
    strncpy(buf, prefix, length);
    CUTIL_GenerateRandomString(buf + length, size - length);
  } else {
    CUTIL_GenerateRandomString(buf, size);
  }
  return buf;
}


x86 assembly (clang, -O0):
<CUTIL_GenerateRandomStringWithPrefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a2 <CUTIL_GenerateRandomStringWithPrefix+0x72>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1177 <CUTIL_GenerateRandomStringWithPrefix+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11b7 <CUTIL_GenerateRandomStringWithPrefix+0x87>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   1040 <CUTIL_GenerateRandomString@plt>
jmp    11af <CUTIL_GenerateRandomStringWithPrefix+0x7f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <CUTIL_GenerateRandomString@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CUTIL_GenerateRandomStringWithPrefix>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
test   %rdi,%rdi
je     1155 <CUTIL_GenerateRandomStringWithPrefix+0x25>
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    %r15,%rax
jbe    115a <CUTIL_GenerateRandomStringWithPrefix+0x2a>
xor    %r14d,%r14d
jmp    117a <CUTIL_GenerateRandomStringWithPrefix+0x4a>
mov    %r14,%rdi
jmp    1172 <CUTIL_GenerateRandomStringWithPrefix+0x42>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
lea    (%r14,%r12,1),%rdi
sub    %r12,%r15
mov    %r15,%rsi
call   1040 <CUTIL_GenerateRandomString@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @CUTIL_GenerateRandomStringWithPrefix(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %30
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = load i64, i64* %7
%16 = icmp ugt i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
store i8* null, i8** %4
br label %36
18: ; preds = %11
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = load i64, i64* %8
%22 = call i32 @strncpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %6
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i64, i64* %7
%27 = load i64, i64* %8
%28 = sub i64 %26, %27
%29 = call i32 @CUTIL_GenerateRandomString(i8* %25, i64 %28)
br label %34
30: ; preds = %3
%31 = load i8*, i8** %6
%32 = load i64, i64* %7
%33 = call i32 @CUTIL_GenerateRandomString(i8* %31, i64 %32)
br label %34
34: ; preds = %30, %18
%35 = load i8*, i8** %6
store i8* %35, i8** %4
br label %36
36: ; preds = %34, %17
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
define i8* @CUTIL_GenerateRandomStringWithPrefix(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* %0)
%7 = icmp ugt i64 %6, %2
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %6)
%10 = getelementptr inbounds i8, i8* %1, i64 %6
%11 = sub i64 %2, %6
%12 = tail call i32 @CUTIL_GenerateRandomString(i8* %10, i64 %11)
br label %15
13: ; preds = %3
%14 = tail call i32 @CUTIL_GenerateRandomString(i8* %1, i64 %2)
br label %15
15: ; preds = %13, %8, %5
%16 = phi i8* [ null, %5 ], [ %1, %8 ], [ %1, %13 ]
ret i8* %16
}