#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;
};
struct sockaddr {
  int sa_family;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
#define AF_INET 128
int /*<<< orphan*/ change_port(int /*<<< orphan*/ *);
int /*<<< orphan*/ debug_printf(char *, int, int);
int real_bind(int, struct sockaddr const *, int /*<<< orphan*/);
int bind(int fd, const struct sockaddr *sk, socklen_t sl) {
  switch (sk->sa_family) {
  case AF_INET: {
    struct sockaddr_in *lsk_in = (struct sockaddr_in *)sk;
    if (change_port(&lsk_in->sin_port))
      ;
  } break;
  default:
    debug_printf("[libmultid::bind()] address family unknown af=%d fd=%d\n",
                 sk->sa_family, fd);
    break;
  }
  return real_bind(fd, sk, sl);
}


x86 assembly (clang, -O0):
<bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    117c <bind+0x4c>
jmp    1158 <bind+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <change_port@plt>
cmp    $0x0,%eax
je     1177 <bind+0x47>
jmp    1177 <bind+0x47>
jmp    1191 <bind+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    0xe74(%rip),%rdi
call   1040 <debug_printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <real_bind@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%esi
cmp    $0x80,%esi
jne    1150 <bind+0x20>
mov    %rbx,%rdi
call   1030 <change_port@plt>
jmp    115e <bind+0x2e>
lea    0xea9(%rip),%rdi
mov    %ebp,%edx
call   1040 <debug_printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <real_bind@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
@.str = [56 x i8] c"[libmultid::bind()] address family unknown af=%d fd=%d\0A\00"
define i32 @bind(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
%8 = load %struct.sockaddr*, %struct.sockaddr** %5
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %20 [
i32 128, label %11
]
11: ; preds = %3
%12 = load %struct.sockaddr*, %struct.sockaddr** %5
%13 = bitcast %struct.sockaddr* %12 to %struct.sockaddr_in*
store %struct.sockaddr_in* %13, %struct.sockaddr_in** %7
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%16 = call i32 @change_port(i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
br label %19
19: ; preds = %18, %11
br label %26
20: ; preds = %3
%21 = load %struct.sockaddr*, %struct.sockaddr** %5
%22 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* %4
%25 = call i32 @debug_printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
br label %26
26: ; preds = %20, %19
%27 = load i32, i32* %4
%28 = load %struct.sockaddr*, %struct.sockaddr** %5
%29 = load i32, i32* %6
%30 = call i32 @real_bind(i32 %27, %struct.sockaddr* %28, i32 %29)
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [56 x i8] c"[libmultid::bind()] address family unknown af=%d fd=%d\0A\00"
define i32 @bind(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 128
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @change_port(i32* %4)
br label %11
9: ; preds = %3
%10 = tail call i32 @debug_printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %0)
br label %11
11: ; preds = %9, %7
%12 = tail call i32 @real_bind(i32 %0, %struct.sockaddr* %1, i32 %2)
ret i32 %12
}