#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 zinet_listen(char *, int, int);
int zunix_listen(char *, int);
int zlisten(const char *netpath, int backlog) {
  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 = zinet_listen(_netpath, port, backlog);
  } else {
    fd = zunix_listen(_netpath, backlog);
  }
  return fd;
}


x86 assembly (clang, -O0):
<zlisten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%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   1040 <strchr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11e7 <zlisten+0x97>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x418(%rbp),%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x41c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <zinet_listen@plt>
mov    %eax,-0x420(%rbp)
jmp    11fc <zlisten+0xac>
lea    -0x410(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <zunix_listen@plt>
mov    %eax,-0x420(%rbp)
mov    -0x420(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlisten>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119d <zlisten+0x4d>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %rsp,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1060 <zinet_listen@plt>
jmp    11a7 <zlisten+0x57>
mov    %rsp,%rdi
mov    %ebp,%esi
call   1070 <zunix_listen@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @zlisten(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %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 i32, i32* %4
%24 = call i32 @zinet_listen(i8* %21, i32 %22, i32 %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 i32, i32* %4
%28 = call i32 @zunix_listen(i8* %26, i32 %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 @zlisten(i8* %0, i32 %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 @zinet_listen(i8* %4, i32 %10, i32 %1)
br label %14
12: ; preds = %2
%13 = call i32 @zunix_listen(i8* %4, i32 %1)
br label %14
14: ; preds = %12, %8
%15 = phi i32 [ %11, %8 ], [ %13, %12 ]
ret i32 %15
}