#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 InstanceNumberAsInt();
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 *, int);
int /*<<< orphan*/ stderr;
char *TCPInstanceStr(void) {
  enum { kPortWidth = 4, kFirstPort = 6520 };
  const char kIPPrefix[] = "127.0.0.1:";
  size_t sz = (sizeof kIPPrefix) + kPortWidth;
  char *instance_str = malloc(sz);
  if (!instance_str) {
    fprintf(stderr, "Unable to allocate %zu bytes for instance name\n", sz);
    exit(2);
  }
  int instance_port = InstanceNumberAsInt() - 1 + kFirstPort;
  snprintf(instance_str, sz, "%s%d", kIPPrefix, instance_port);
  return instance_str;
}


x86 assembly (clang, -O0):
<TCPInstanceStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xea1(%rip),%rax
mov    %rax,-0xb(%rbp)
mov    0xe9e(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xe96(%rip),%al
mov    %al,-0x1(%rbp)
movq   $0xf,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ba <TCPInstanceStr+0x6a>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1070 <InstanceNumberAsInt@plt>
sub    $0x1,%eax
add    $0x1978,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xb(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe58(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TCPInstanceStr>:
push   %rbx
sub    $0x10,%rsp
movabs $0x2e302e302e373231,%rax
2e 30 2e
mov    %rax,(%rsp)
movl   $0x3a312e,0x7(%rsp)
mov    $0xf,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ab <TCPInstanceStr+0x5b>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <InstanceNumberAsInt@plt>
lea    0x1977(%rax),%r8d
lea    0xea9(%rip),%rdx
mov    %rsp,%rcx
mov    $0xf,%esi
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0xf,%edx
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.TCPInstanceStr.kIPPrefix = [11 x i8] c"127.0.0.1:\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%d\00"
define i8* @TCPInstanceStr() {
%1 = alloca [11 x i8]
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast [11 x i8]* %1 to i8*
store i64 15, i64* %2
%6 = load i64, i64* %2
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i64, i64* %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %0
%16 = call i32 (...) @InstanceNumberAsInt()
%17 = sub nsw i32 %16, 1
%18 = add nsw i32 %17, 6520
store i32 %18, i32* %4
%19 = load i8*, i8** %3
%20 = load i64, i64* %2
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%22 = load i32, i32* %4
%23 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22)
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@__const.TCPInstanceStr.kIPPrefix = [11 x i8] c"127.0.0.1:\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%d\00"
define i8* @TCPInstanceStr() {
%1 = alloca [11 x i8]
%2 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(15) i8* @malloc(i64 15)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 15)
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %0
%10 = tail call i32 (...) @InstanceNumberAsInt()
%11 = add nsw i32 %10, 6519
%12 = call i32 @snprintf(i8* %3, i64 15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %11)
ret i8* %3
}