#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 servent {
  int /*<<< orphan*/ s_port;
};
struct protoent {
  int /*<<< orphan*/ p_proto;
};

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ assert(int);
struct protoent *getprotobyname(char const *const);
struct servent *getservbyname(char const *const, char const *const);
int ipacl_do_request(int const, int *const, char const *const,
                     int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int ipacl_do_request_s(const int reqport, int *const restrict pfh,
                       const char *const restrict ip,
                       const char *const restrict protocol,
                       const char *const restrict port) {
  struct servent *ps;
  struct protoent *pp;
  assert(reqport >= 0);
  assert(pfh != NULL);
  assert(ip != NULL);
  assert(protocol != NULL);
  assert(port != NULL);
  ps = getservbyname(port, protocol);
  if (ps == NULL)
    return EINVAL;
  pp = getprotobyname(protocol);
  if (pp == NULL)
    return EINVAL;
  return ipacl_do_request(reqport, pfh, ip, pp->p_proto, ntohs(ps->s_port));
}


x86 assembly (clang, -O0):
<ipacl_do_request_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
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>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <getservbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f1 <ipacl_do_request_s+0xa1>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <ipacl_do_request_s+0x10d>
mov    -0x20(%rbp),%rdi
call   1060 <getprotobyname@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121a <ipacl_do_request_s+0xca>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <ipacl_do_request_s+0x10d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohs@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    %eax,%r8d
call   1040 <ipacl_do_request@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipacl_do_request_s>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <assert@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <getservbyname@plt>
test   %rax,%rax
je     11ee <ipacl_do_request_s+0x9e>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <getprotobyname@plt>
test   %rax,%rax
je     11ee <ipacl_do_request_s+0x9e>
mov    (%rax),%ebx
mov    0x0(%rbp),%edi
call   1070 <ntohs@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %eax,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ipacl_do_request@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.servent = type { i32 }
%struct.protoent = type { i32 }
@EINVAL = global i32 0
define i32 @ipacl_do_request_s(i32 %0, i32* noalias %1, i8* noalias %2, i8* noalias %3, i8* noalias %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca %struct.servent*
%13 = alloca %struct.protoent*
store i32 %0, i32* %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32*, i32** %8
%19 = icmp ne i32* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i8*, i8** %10
%27 = icmp ne i8* %26, null
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i8*, i8** %11
%31 = icmp ne i8* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %11
%35 = load i8*, i8** %10
%36 = call %struct.servent* @getservbyname(i8* %34, i8* %35)
store %struct.servent* %36, %struct.servent** %12
%37 = load %struct.servent*, %struct.servent** %12
%38 = icmp eq %struct.servent* %37, null
br i1 %38, label %39, label %41
39: ; preds = %5
%40 = load i32, i32* @EINVAL
store i32 %40, i32* %6
br label %60
41: ; preds = %5
%42 = load i8*, i8** %10
%43 = call %struct.protoent* @getprotobyname(i8* %42)
store %struct.protoent* %43, %struct.protoent** %13
%44 = load %struct.protoent*, %struct.protoent** %13
%45 = icmp eq %struct.protoent* %44, null
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = load i32, i32* @EINVAL
store i32 %47, i32* %6
br label %60
48: ; preds = %41
%49 = load i32, i32* %7
%50 = load i32*, i32** %8
%51 = load i8*, i8** %9
%52 = load %struct.protoent*, %struct.protoent** %13
%53 = getelementptr inbounds %struct.protoent, %struct.protoent* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = load %struct.servent*, %struct.servent** %12
%56 = getelementptr inbounds %struct.servent, %struct.servent* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @ntohs(i32 %57)
%59 = call i32 @ipacl_do_request(i32 %49, i32* %50, i8* %51, i32 %54, i32 %58)
store i32 %59, i32* %6
br label %60
60: ; preds = %48, %46, %39
%61 = load i32, i32* %6
ret i32 %61
}

LLVM IR (-O2):
%struct.servent = type { i32 }
%struct.protoent = type { i32 }
@EINVAL = global i32 0
define i32 @ipacl_do_request_s(i32 %0, i32* noalias %1, i8* noalias %2, i8* noalias %3, i8* noalias %4) {
%6 = xor i32 %0, -1
%7 = lshr i32 %6, 31
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i32* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i8* %2, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp ne i8* %3, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ne i8* %4, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call %struct.servent* @getservbyname(i8* %4, i8* %3)
%22 = icmp eq %struct.servent* %21, null
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = load i32, i32* @EINVAL
br label %37
25: ; preds = %5
%26 = tail call %struct.protoent* @getprotobyname(i8* %3)
%27 = icmp eq %struct.protoent* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* @EINVAL
br label %37
30: ; preds = %25
%31 = getelementptr inbounds %struct.protoent, %struct.protoent* %26, i64 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.servent, %struct.servent* %21, i64 0, i32 0
%34 = load i32, i32* %33
%35 = tail call i32 @ntohs(i32 %34)
%36 = tail call i32 @ipacl_do_request(i32 %0, i32* %1, i8* %2, i32 %32, i32 %35)
br label %37
37: ; preds = %30, %28, %23
%38 = phi i32 [ %24, %23 ], [ %29, %28 ], [ %36, %30 ]
ret i32 %38
}