#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 {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ ipacl_close(int);
int ipacl_do_request_addr(int, int *const, struct sockaddr const *const,
                          unsigned int const);
int ipacl_open(int *);
int ipacl_request_addr(int *const restrict pfh,
                       const struct sockaddr *const restrict addr,
                       const unsigned int protocol) {
  int fh;
  int rc;
  assert(pfh != NULL);
  assert(addr != NULL);
  assert(protocol <= 65535u);
  assert((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6));
  if ((rc = ipacl_open(&fh)) != 0)
    return rc;
  rc = ipacl_do_request_addr(fh, pfh, addr, protocol);
  ipacl_close(fh);
  return rc;
}


x86 assembly (clang, -O0):
<ipacl_request_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffff,-0x1c(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e4d(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x25(%rbp)
je     11be <ipacl_request_addr+0x7e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
call   1030 <ipacl_open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11eb <ipacl_request_addr+0xab>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <ipacl_request_addr+0xcf>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <ipacl_do_request_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <ipacl_close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipacl_request_addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0x10000,%r14d
setb   %dil
call   1050 <assert@plt>
mov    (%rbx),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
sete   %cl
mov    0x2e4b(%rip),%rdx
cmp    (%rdx),%rax
sete   %al
or     %cl,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0x4(%rsp),%rdi
call   1030 <ipacl_open@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11d2 <ipacl_request_addr+0x92>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <ipacl_do_request_addr@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
call   1060 <ipacl_close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @ipacl_request_addr(i32* noalias %0, %struct.sockaddr* noalias %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load %struct.sockaddr*, %struct.sockaddr** %6
%15 = icmp ne %struct.sockaddr* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %7
%19 = icmp ule i32 %18, 65535
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load %struct.sockaddr*, %struct.sockaddr** %6
%23 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* @AF_INET
%26 = icmp eq i64 %24, %25
br i1 %26, label %33, label %27
27: ; preds = %3
%28 = load %struct.sockaddr*, %struct.sockaddr** %6
%29 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @AF_INET6
%32 = icmp eq i64 %30, %31
br label %33
33: ; preds = %27, %3
%34 = phi i1 [ true, %3 ], [ %32, %27 ]
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = call i32 @ipacl_open(i32* %8)
store i32 %37, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = load i32, i32* %9
store i32 %40, i32* %4
br label %50
41: ; preds = %33
%42 = load i32, i32* %8
%43 = load i32*, i32** %5
%44 = load %struct.sockaddr*, %struct.sockaddr** %6
%45 = load i32, i32* %7
%46 = call i32 @ipacl_do_request_addr(i32 %42, i32* %43, %struct.sockaddr* %44, i32 %45)
store i32 %46, i32* %9
%47 = load i32, i32* %8
%48 = call i32 @ipacl_close(i32 %47)
%49 = load i32, i32* %9
store i32 %49, i32* %4
br label %50
50: ; preds = %41, %39
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define i32 @ipacl_request_addr(i32* noalias %0, %struct.sockaddr* noalias %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp ne i32* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne %struct.sockaddr* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ult i32 %2, 65536
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET
%18 = icmp eq i64 %16, %17
%19 = load i64, i64* @AF_INET6
%20 = icmp eq i64 %16, %19
%21 = select i1 %18, i1 true, i1 %20
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = call i32 @ipacl_open(i32* %4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %3
%27 = load i32, i32* %4
%28 = call i32 @ipacl_do_request_addr(i32 %27, i32* %0, %struct.sockaddr* %1, i32 %2)
%29 = load i32, i32* %4
%30 = call i32 @ipacl_close(i32 %29)
br label %31
31: ; preds = %3, %26
%32 = phi i32 [ %28, %26 ], [ %24, %3 ]
ret i32 %32
}