#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int create_serv(int sockfd, int port) {
  struct sockaddr_in srvaddr;
  bzero(&srvaddr, sizeof(struct sockaddr));
  srvaddr.sin_port = htons(port);
  srvaddr.sin_family = AF_INET;
  srvaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sockfd, (struct sockaddr *)&srvaddr, sizeof(struct sockaddr)) < 0) {
    return (0);
  }
  if (listen(sockfd, 1) < 0) {
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<create_serv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    11bb <create_serv+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <create_serv+0x95>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <listen@plt>
cmp    $0x0,%rax
jge    11de <create_serv+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <create_serv+0x95>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_serv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     11be <create_serv+0x6e>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <listen@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
jmp    11c0 <create_serv+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define i32 @create_serv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 @bzero(%struct.sockaddr_in* %6, i32 4)
%8 = load i32, i32* %5
%9 = call i32 @htons(i32 %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %4
%18 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%19 = call i64 @bind(i32 %17, %struct.sockaddr* %18, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 0, i32* %3
br label %28
22: ; preds = %2
%23 = load i32, i32* %4
%24 = call i64 @listen(i32 %23, i32 1)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %3
br label %28
27: ; preds = %22
store i32 1, i32* %3
br label %28
28: ; preds = %27, %26, %21
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define i32 @create_serv(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = call i32 @bzero(%struct.sockaddr_in* %3, i32 4)
%6 = tail call i32 @htons(i32 %1)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = tail call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%14 = call i64 @bind(i32 %0, %struct.sockaddr* %13, i32 4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %2
%17 = call i64 @listen(i32 %0, i32 1)
%18 = lshr i64 %17, 63
%19 = trunc i64 %18 to i32
%20 = xor i32 %19, 1
br label %21
21: ; preds = %16, %2
%22 = phi i32 [ 0, %2 ], [ %20, %16 ]
ret i32 %22
}