#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ byte_copy(int /*<<< orphan*/ *, int, unsigned char const *);
int /*<<< orphan*/ byte_zero(struct sockaddr_in *, int);
int socket_bind(int fd, const unsigned char *ip, const unsigned char *port) {
  struct sockaddr_in sa;
  byte_zero(&sa, sizeof sa);
  byte_copy(&sa.sin_addr, 4, ip);
  byte_copy(&sa.sin_port, 2, port);
  return bind(fd, (struct sockaddr *)&sa, sizeof sa);
}


x86 assembly (clang, -O0):
<socket_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1030 <byte_zero@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4,%esi
call   1050 <byte_copy@plt>
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2,%esi
call   1050 <byte_copy@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <bind@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_bind>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
call   1030 <byte_zero@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1050 <byte_copy@plt>
mov    %rbp,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1050 <byte_copy@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <bind@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i32 @socket_bind(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = call i32 @byte_zero(%struct.sockaddr_in* %7, i32 8)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%10 = load i8*, i8** %5
%11 = call i32 @byte_copy(i32* %9, i32 4, i8* %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%13 = load i8*, i8** %6
%14 = call i32 @byte_copy(i32* %12, i32 2, i8* %13)
%15 = load i32, i32* %4
%16 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%17 = call i32 @bind(i32 %15, %struct.sockaddr* %16, i32 8)
ret i32 %17
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i32 @socket_bind(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = call i32 @byte_zero(%struct.sockaddr_in* %4, i32 8)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%8 = call i32 @byte_copy(i32* %7, i32 4, i8* %1)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%10 = call i32 @byte_copy(i32* %9, i32 2, i8* %2)
%11 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%12 = call i32 @bind(i32 %0, %struct.sockaddr* %11, i32 8)
ret i32 %12
}