#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 *InstanceNumberAsStr();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
char *malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
char *USBInstanceStr(void) {
  const char kSerialNumberPrefix[] = "CUTTLEFISHCVD";
  const char *instance = InstanceNumberAsStr();
  size_t sz = (sizeof kSerialNumberPrefix) + strlen(instance);
  char *instance_str = malloc(sz);
  if (!instance_str) {
    fprintf(stderr, "Unable to allocate %zu bytes for instance name\n", sz);
    exit(2);
  }
  snprintf(instance_str, sz, "%s%s", kSerialNumberPrefix, instance);
  return instance_str;
}


x86 assembly (clang, -O0):
<USBInstanceStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xe89(%rip),%ax
mov    %ax,-0x2(%rbp)
mov    $0x0,%al
call   1070 <InstanceNumberAsStr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xe,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11de <USBInstanceStr+0x7e>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0xe(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe49(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<USBInstanceStr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0x44564348534946,%rax
mov    %rax,0x6(%rsp)
movabs $0x4946454c54545543,%rax
45 46 49
mov    %rax,(%rsp)
xor    %eax,%eax
call   1070 <InstanceNumberAsStr@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
add    $0xe,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d4 <USBInstanceStr+0x74>
mov    %rax,%r15
lea    0xe88(%rip),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.USBInstanceStr.kSerialNumberPrefix = [14 x i8] c"CUTTLEFISHCVD\00"
@stderr = global i32 0
@.str = [48 x i8] c"Unable to allocate %zu bytes for instance name\0A\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @USBInstanceStr() {
%1 = alloca [14 x i8]
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast [14 x i8]* %1 to i8*
%6 = call i8* (...) @InstanceNumberAsStr()
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add i64 14, %8
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i64, i64* %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %0
%20 = load i8*, i8** %4
%21 = load i64, i64* %3
%22 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%23 = load i8*, i8** %2
%24 = call i32 @snprintf(i8* %20, i64 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
@__const.USBInstanceStr.kSerialNumberPrefix = [14 x i8] c"CUTTLEFISHCVD\00"
@stderr = global i32 0
@.str = [48 x i8] c"Unable to allocate %zu bytes for instance name\0A\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @USBInstanceStr() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = tail call i8* (...) @InstanceNumberAsStr()
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = add i64 %4, 14
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %5)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %0
%13 = call i32 @snprintf(i8* %6, i64 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
ret i8* %6
}