#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ bz(struct sockaddr_in *, int);
int /*<<< orphan*/ u16_pb(char *, int /*<<< orphan*/);
int sck_bind4(int s, char ip[4], uint16_t p) {
  struct sockaddr_in si;
  bz(&si, sizeof si);
  si.sin_family = AF_INET;
  u16_pb((char *)&si.sin_port, p);
  if (ip)
    *(uint32_t *)&si.sin_addr = *(uint32_t *)ip;
  else
    si.sin_addr.s_addr = INADDR_ANY;
  return bind(s, (const struct sockaddr *)&si, sizeof si);
}


x86 assembly (clang, -O0):
<sck_bind4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1040 <bz@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x14(%rbp),%esi
call   1030 <u16_pb@plt>
cmpq   $0x0,-0x10(%rbp)
je     1185 <sck_bind4+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1191 <sck_bind4+0x61>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sck_bind4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1040 <bz@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
mov    %ebp,%esi
call   1030 <u16_pb@plt>
test   %rbx,%rbx
jne    1179 <sck_bind4+0x49>
mov    0x2e67(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 @sck_bind4(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = call i32 @bz(%struct.sockaddr_in* %7, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%12 = bitcast i32* %11 to i8*
%13 = load i32, i32* %6
%14 = call i32 @u16_pb(i8* %12, i32 %13)
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%22 = bitcast %struct.TYPE_2__* %21 to i32*
store i32 %20, i32* %22
br label %27
23: ; preds = %3
%24 = load i32, i32* @INADDR_ANY
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
br label %27
27: ; preds = %23, %17
%28 = load i32, i32* %4
%29 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
ret i32 %30
}

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 @sck_bind4(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = call i32 @bz(%struct.sockaddr_in* %4, i32 12)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%10 = bitcast i32* %9 to i8*
%11 = call i32 @u16_pb(i8* %10, i32 %2)
%12 = icmp eq i8* %1, null
%13 = bitcast i8* %1 to i32*
%14 = select i1 %12, i32* @INADDR_ANY, i32* %13
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%18 = call i32 @bind(i32 %0, %struct.sockaddr* %17, i32 12)
ret i32 %18
}