#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 atoi(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int zhost_connect(char *, int, long);
int zunix_connect(char *, long);
int zconnect(const char *netpath, long timeout) {
  char _netpath[1024];
  char *p;
  int port;
  int fd;
  fd = 0;
  strncpy(_netpath, netpath, 1000);
  p = strchr(_netpath, ':');
  if (p) {
    *p = 0;
    port = atoi(p + 1);
    fd = zhost_connect(_netpath, port, timeout);
  } else {
    fd = zunix_connect(_netpath, timeout);
  }
  return fd;
}


x86 assembly (clang, -O0):
<zconnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <strncpy@plt>
lea    -0x410(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11e9 <zconnect+0x99>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x418(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x41c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <zhost_connect@plt>
mov    %eax,-0x420(%rbp)
jmp    11ff <zconnect+0xaf>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <zunix_connect@plt>
mov    %eax,-0x420(%rbp)
mov    -0x420(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zconnect>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a0 <zconnect+0x50>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %rsp,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1040 <zhost_connect@plt>
jmp    11ab <zconnect+0x5b>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <zunix_connect@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @zconnect(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strncpy(i8* %9, i8* %10, i32 1000)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 58)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i8*, i8** %6
store i8 0, i8* %17
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %7
%23 = load i64, i64* %4
%24 = call i32 @zhost_connect(i8* %21, i32 %22, i64 %23)
store i32 %24, i32* %8
br label %29
25: ; preds = %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = load i64, i64* %4
%28 = call i32 @zunix_connect(i8* %26, i64 %27)
store i32 %28, i32* %8
br label %29
29: ; preds = %25, %16
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
define i32 @zconnect(i8* %0, i64 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strncpy(i8* %4, i8* %0, i32 1000)
%6 = call i8* @strchr(i8* %4, i8 signext 58)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
store i8 0, i8* %6
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = call i32 @atoi(i8* %9)
%11 = call i32 @zhost_connect(i8* %4, i32 %10, i64 %1)
br label %14
12: ; preds = %2
%13 = call i32 @zunix_connect(i8* %4, i64 %1)
br label %14
14: ; preds = %12, %8
%15 = phi i32 [ %11, %8 ], [ %13, %12 ]
ret i32 %15
}