#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*/ assert(char const *);
char *strchr(char *, char);
int tcatoi(char *);
int /*<<< orphan*/ tcfree(char *);
char *tcstrdup(char const *);
int /*<<< orphan*/ tcstrtrim(char *);
char *ttbreakservexpr(const char *expr, int *pp) {
  assert(expr);
  char *host = tcstrdup(expr);
  char *pv = strchr(host, '#');
  if (pv)
    *pv = '\0';
  int port = -1;
  pv = strchr(host, ':');
  if (pv) {
    *(pv++) = '\0';
    if (*pv >= '0' && *pv <= '9')
      port = tcatoi(pv);
  }
  if (port < 0)
    port = 1978;
  if (pp)
    *pp = port;
  tcstrtrim(host);
  if (*host == '\0') {
    tcfree(host);
    host = tcstrdup("127.0.0.1");
  }
  return host;
}


x86 assembly (clang, -O0):
<ttbreakservexpr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1080 <tcstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11aa <ttbreakservexpr+0x4a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1211 <ttbreakservexpr+0xb1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     120c <ttbreakservexpr+0xac>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     120c <ttbreakservexpr+0xac>
mov    -0x20(%rbp),%rdi
call   1050 <tcatoi@plt>
mov    %eax,-0x24(%rbp)
jmp    1211 <ttbreakservexpr+0xb1>
cmpl   $0x0,-0x24(%rbp)
jge    1222 <ttbreakservexpr+0xc2>
movl   $0x7ba,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1236 <ttbreakservexpr+0xd6>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <tcstrtrim@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1268 <ttbreakservexpr+0x108>
mov    -0x18(%rbp),%rdi
call   1070 <tcfree@plt>
lea    0xda1(%rip),%rdi
call   1080 <tcstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttbreakservexpr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1080 <tcstrdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     118f <ttbreakservexpr+0x2f>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,%rdi
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11c0 <ttbreakservexpr+0x60>
movb   $0x0,(%rdi)
mov    0x1(%rdi),%cl
add    $0xd0,%cl
cmp    $0x9,%cl
ja     11c0 <ttbreakservexpr+0x60>
add    $0x1,%rdi
call   1050 <tcatoi@plt>
test   %r14,%r14
je     11d2 <ttbreakservexpr+0x72>
test   %eax,%eax
mov    $0x7ba,%ecx
cmovns %eax,%ecx
mov    %ecx,(%r14)
mov    %rbx,%rdi
call   1030 <tcstrtrim@plt>
cmpb   $0x0,(%rbx)
je     11ea <ttbreakservexpr+0x8a>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1070 <tcfree@plt>
lea    0xe07(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <tcstrdup@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
define i8* @ttbreakservexpr(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %3
%11 = call i8* @tcstrdup(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i8* @strchr(i8* %12, i8 signext 35)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i8*, i8** %6
store i8 0, i8* %17
br label %18
18: ; preds = %16, %2
store i32 -1, i32* %7
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 58)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
store i8 0, i8* %24
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sge i32 %28, 48
br i1 %29, label %30, label %38
30: ; preds = %23
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 57
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = call i32 @tcatoi(i8* %36)
store i32 %37, i32* %7
br label %38
38: ; preds = %35, %30, %23
br label %39
39: ; preds = %38, %18
%40 = load i32, i32* %7
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1978, i32* %7
br label %43
43: ; preds = %42, %39
%44 = load i32*, i32** %4
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %7
%48 = load i32*, i32** %4
store i32 %47, i32* %48
br label %49
49: ; preds = %46, %43
%50 = load i8*, i8** %5
%51 = call i32 @tcstrtrim(i8* %50)
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %49
%57 = load i8*, i8** %5
%58 = call i32 @tcfree(i8* %57)
%59 = call i8* @tcstrdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %59, i8** %5
br label %60
60: ; preds = %56, %49
%61 = load i8*, i8** %5
ret i8* %61
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
define i8* @ttbreakservexpr(i8* %0, i32* writeonly %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i8* @tcstrdup(i8* %0)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 35)
%6 = icmp eq i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %2
store i8 0, i8* %5
br label %8
8: ; preds = %7, %2
%9 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 58)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
store i8 0, i8* %9
%13 = load i8, i8* %12
%14 = add i8 %13, -48
%15 = icmp ult i8 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @tcatoi(i8* %12)
br label %18
18: ; preds = %11, %16, %8
%19 = phi i32 [ %17, %16 ], [ -1, %11 ], [ -1, %8 ]
%20 = icmp eq i32* %1, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = icmp slt i32 %19, 0
%23 = select i1 %22, i32 1978, i32 %19
store i32 %23, i32* %1
br label %24
24: ; preds = %21, %18
%25 = tail call i32 @tcstrtrim(i8* %4)
%26 = load i8, i8* %4
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = tail call i32 @tcfree(i8* %4)
%30 = tail call i8* @tcstrdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %28, %24
%32 = phi i8* [ %30, %28 ], [ %4, %24 ]
ret i8* %32
}