#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int atoi(char *);
int can_tcp_open(char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
int sock__open_tcp(const char *addr) {
  char buffer[256];
  strlcpy(buffer, addr, sizeof(buffer));
  char *portptr = strchr(buffer, ':');
  int port = 5555;
  if (portptr) {
    *portptr++ = '\0';
    port = atoi(portptr);
  }
  return can_tcp_open(buffer, port);
}


x86 assembly (clang, -O0):
<sock__open_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1050 <strlcpy@plt>
lea    -0x110(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x118(%rbp)
movl   $0x15b3,-0x11c(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11be <sock__open_tcp+0x7e>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x0,(%rax)
mov    -0x118(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x11c(%rbp),%esi
call   1030 <can_tcp_open@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock__open_tcp>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1050 <strlcpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <sock__open_tcp+0x40>
mov    %rax,%rdi
add    $0x1,%rdi
movb   $0x0,(%rax)
call   1060 <atoi@plt>
mov    %eax,%esi
jmp    1185 <sock__open_tcp+0x45>
mov    $0x15b3,%esi
mov    %rsp,%rdi
call   1030 <can_tcp_open@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @sock__open_tcp(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strlcpy(i8* %6, i8* %7, i32 256)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i8* @strchr(i8* %9, i8 signext 58)
store i8* %10, i8** %4
store i32 5555, i32* %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
store i8 0, i8* %14
%16 = load i8*, i8** %4
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %5
br label %18
18: ; preds = %13, %1
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* %5
%21 = call i32 @can_tcp_open(i8* %19, i32 %20)
ret i32 %21
}

LLVM IR (-O2):
define i32 @sock__open_tcp(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @strlcpy(i8* %3, i8* %0, i32 256)
%5 = call i8* @strchr(i8* %3, i8 signext 58)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %5
%9 = call i32 @atoi(i8* %8)
br label %10
10: ; preds = %7, %1
%11 = phi i32 [ %9, %7 ], [ 5555, %1 ]
%12 = call i32 @can_tcp_open(i8* %3, i32 %11)
ret i32 %12
}