#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 {
  char const *s_name;
  int s_port;
  char const *s_proto;
};

/* Variables and functions */
struct servent *getservbyport(int, char const *);
int /*<<< orphan*/ printf(char *, char const *, int, char const *);
int _getservbyport(char const *progname, int port, char const *protocol) {
  struct servent *se;
  printf("%s: Testing getservbyport(): %d/%s\n", progname, port, protocol);
  if ((se = getservbyport(port, protocol)) == NULL)
    return 0;
  printf("%s\t%d/%s\n", se->s_name, se->s_port, se->s_proto);
  return 0;
}


x86 assembly (clang, -O0):
<_getservbyport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <getservbyport@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1170 <_getservbyport+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1199 <_getservbyport+0x79>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getservbyport>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%rsi
lea    0xece(%rip),%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <getservbyport@plt>
test   %rax,%rax
je     1161 <_getservbyport+0x41>
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    0x10(%rax),%rcx
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.servent = type { i8*, i32, i8* }
@.str = [36 x i8] c"%s: Testing getservbyport(): %d/%s\0A\00"
@.str.1 = [10 x i8] c"%s\09%d/%s\0A\00"
define i32 @_getservbyport(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.servent*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = load i8*, i8** %7
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10, i8* %11)
%13 = load i32, i32* %6
%14 = load i8*, i8** %7
%15 = call %struct.servent* @getservbyport(i32 %13, i8* %14)
store %struct.servent* %15, %struct.servent** %8
%16 = icmp eq %struct.servent* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %29
18: ; preds = %3
%19 = load %struct.servent*, %struct.servent** %8
%20 = getelementptr inbounds %struct.servent, %struct.servent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = load %struct.servent*, %struct.servent** %8
%23 = getelementptr inbounds %struct.servent, %struct.servent* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load %struct.servent*, %struct.servent** %8
%26 = getelementptr inbounds %struct.servent, %struct.servent* %25, i32 0, i32 2
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %24, i8* %27)
store i32 0, i32* %4
br label %29
29: ; preds = %18, %17
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.servent = type { i8*, i32, i8* }
@.str = [36 x i8] c"%s: Testing getservbyport(): %d/%s\0A\00"
@.str.1 = [10 x i8] c"%s\09%d/%s\0A\00"
define i32 @_getservbyport(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i8* %2)
%5 = tail call %struct.servent* @getservbyport(i32 %1, i8* %2)
%6 = icmp eq %struct.servent* %5, null
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.servent, %struct.servent* %5, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = getelementptr inbounds %struct.servent, %struct.servent* %5, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.servent, %struct.servent* %5, i64 0, i32 2
%13 = load i8*, i8** %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %11, i8* %13)
br label %15
15: ; preds = %3, %7
ret i32 0
}