#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 port_attributes {
  int dummy;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct port_attributes *);
struct port_attributes *get_port_attribs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show_port_info(struct port_attributes *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int get_host_from_vport(struct dirent *dp, void *arg __attribute__((unused))) {
  if (!strncmp(dp->d_name, "host", strlen("host"))) {
    struct port_attributes *port_attrs;
    port_attrs = get_port_attribs(dp->d_name);
    if (!port_attrs)
      return 0;
    printf("\n");
    show_port_info(port_attrs);
    free(port_attrs);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_host_from_vport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe80(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe6f(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11e3 <get_host_from_vport+0x83>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <get_port_attribs@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c5 <get_host_from_vport+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11ea <get_host_from_vport+0x8a>
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <show_port_info@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_host_from_vport>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%ebp
lea    0xe90(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
jne    11b1 <get_host_from_vport+0x51>
mov    (%rbx),%edi
call   1070 <get_port_attribs@plt>
test   %rax,%rax
je     11b1 <get_host_from_vport+0x51>
mov    %rax,%rbx
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1080 <show_port_info@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.port_attributes = type { i32 }
@.str = [5 x i8] c"host\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @get_host_from_vport(%struct.dirent* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.dirent*
%5 = alloca i8*
%6 = alloca %struct.port_attributes*
store %struct.dirent* %0, %struct.dirent** %4
store i8* %1, i8** %5
%7 = load %struct.dirent*, %struct.dirent** %4
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @strncmp(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %2
%14 = load %struct.dirent*, %struct.dirent** %4
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call %struct.port_attributes* @get_port_attribs(i32 %16)
store %struct.port_attributes* %17, %struct.port_attributes** %6
%18 = load %struct.port_attributes*, %struct.port_attributes** %6
%19 = icmp ne %struct.port_attributes* %18, null
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 0, i32* %3
br label %28
21: ; preds = %13
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = load %struct.port_attributes*, %struct.port_attributes** %6
%24 = call i32 @show_port_info(%struct.port_attributes* %23)
%25 = load %struct.port_attributes*, %struct.port_attributes** %6
%26 = call i32 @free(%struct.port_attributes* %25)
br label %27
27: ; preds = %21, %2
store i32 0, i32* %3
br label %28
28: ; preds = %27, %20
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
%struct.port_attributes = type { i32 }
@.str = [5 x i8] c"host\00"
define i32 @get_host_from_vport(%struct.dirent* nocapture %0, i8* nocapture readnone %1) {
%3 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strncmp(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i32, i32* %3
%10 = tail call %struct.port_attributes* @get_port_attribs(i32 %9)
%11 = icmp eq %struct.port_attributes* %10, null
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i32 @putchar(i32 10)
%14 = tail call i32 @show_port_info(%struct.port_attributes* %10)
%15 = tail call i32 @free(%struct.port_attributes* %10)
br label %16
16: ; preds = %12, %8, %2
ret i32 0
}