#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ ypbr;
struct TYPE_3__ {
  int /*<<< orphan*/ ypbind_binding_port;
  int /*<<< orphan*/ ypbind_binding_addr;
};
struct TYPE_4__ {
  TYPE_1__ ypbind_bindinfo;
};
struct ypbind_resp {
  TYPE_2__ ypbind_respbody;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ straddr;
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ dir;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gettext(char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int ntohs(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int pread(int, struct ypbind_resp *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
void dump_binding(const char *dir, const char *domain, int version) {
  char path[sizeof(dir) + strlen(domain) + 3 * sizeof(unsigned) + 3];
  snprintf(path, sizeof(path), "%s/%s.%u", dir, domain, version);
  {
    int fd;
    fd = open(path, O_RDONLY);
    if (fd >= 0) {
      struct ypbind_resp ypbr;
      if (pread(fd, &ypbr, sizeof(ypbr), 2) == sizeof(ypbr)) {
        char straddr[INET_ADDRSTRLEN];
        struct sockaddr_in sa;
        sa.sin_family = AF_INET;
        sa.sin_addr = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr;
        inet_ntop(sa.sin_family, &sa.sin_addr, straddr, sizeof(straddr));
        printf("Dump of %s:\n", path);
        printf("\tAddress: %s\n", straddr);
        printf("\tPort: %i\n",
               ntohs(ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port));
      } else
        fprintf(stderr, gettext("Error reading %s: %m\n"), path);
      close(fd);
    } else
      fprintf(stderr, gettext("Error opening %s: %m\n"), path);
  }
}


x86 assembly (clang, -O0):
<dump_binding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    %rcx,%rax
add    $0x17,%rax
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
add    $0x26,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
lea    0xe05(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x58(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1309 <dump_binding+0x169>
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
mov    $0x2,%ecx
call   10c0 <pread@plt>
cltq
cmp    $0x8,%rax
jne    12d5 <dump_binding+0x135>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    0x2d74(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x4c(%rbp)
mov    -0x34(%rbp),%ecx
mov    %ecx,-0x50(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x58(%rbp),%rsi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %eax,%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
jmp    12fc <dump_binding+0x15c>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    0xd47(%rip),%rdi
call   1050 <gettext@plt>
mov    -0x64(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rsi
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
jmp    1330 <dump_binding+0x190>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
lea    0xd29(%rip),%rdi
call   1050 <gettext@plt>
mov    -0x68(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rsi
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_binding>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
cltq
lea    0x17(%rax),%esi
mov    %rsp,%r12
add    $0x26,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe23(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rcx
mov    %rbx,%r8
mov    %r14d,%r9d
call   1070 <snprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     12a5 <dump_binding+0x105>
mov    %eax,%r14d
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
mov    $0x2,%ecx
call   10c0 <pread@plt>
cmp    $0x8,%eax
jne    12c9 <dump_binding+0x129>
mov    %rsp,%rbx
mov    0x2d96(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r15
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    %edi,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rsi
mov    %r15,%rdx
call   1030 <inet_ntop@plt>
lea    0xd9c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd98(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   10a0 <ntohs@plt>
lea    0xd8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rsp
jmp    12eb <dump_binding+0x14b>
mov    0x2d24(%rip),%rax
mov    (%rax),%ebx
lea    0xd90(%rip),%rdi
call   1050 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
mov    %r12,%rdx
call   1090 <fprintf@plt>
jmp    12f3 <dump_binding+0x153>
mov    0x2d00(%rip),%rax
mov    (%rax),%ebx
lea    0xd56(%rip),%rdi
call   1050 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
mov    %r12,%rdx
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ypbind_resp = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32 }
@.str = [9 x i8] c"%s/%s.%u\00"
@O_RDONLY = global i32 0
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"Dump of %s:\0A\00"
@.str.2 = [14 x i8] c"\09Address: %s\0A\00"
@.str.3 = [11 x i8] c"\09Port: %i\0A\00"
@stderr = global i32 0
@.str.4 = [22 x i8] c"Error reading %s: %m\0A\00"
@.str.5 = [22 x i8] c"Error opening %s: %m\0A\00"
define void @dump_binding(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca %struct.ypbind_resp
%11 = alloca i8*
%12 = alloca i64
%13 = alloca %struct.sockaddr_in
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = add i64 8, %16
%18 = add i64 %17, 12
%19 = add i64 %18, 3
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8, i64 %19
store i64 %19, i64* %8
%22 = trunc i64 %19 to i32
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = call i32 @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %21, i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %69
31: ; preds = %3
%32 = load i32, i32* %9
%33 = call i32 @pread(i32 %32, %struct.ypbind_resp* %10, i32 8, i32 2)
%34 = sext i32 %33 to i64
%35 = icmp eq i64 %34, 8
br i1 %35, label %36, label %62
36: ; preds = %31
%37 = load i32, i32* @INET_ADDRSTRLEN
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %11
%40 = alloca i8, i64 %38
store i64 %38, i64* %12
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.ypbind_resp, %struct.ypbind_resp* %10, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %43, i32 0, i32 0
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%51 = trunc i64 %38 to i32
%52 = call i32 @inet_ntop(i32 %49, i32* %50, i8* %40, i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%55 = getelementptr inbounds %struct.ypbind_resp, %struct.ypbind_resp* %10, i32 0, i32 0
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 0
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @ntohs(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %59)
%61 = load i8*, i8** %11
br label %66
62: ; preds = %31
%63 = load i32, i32* @stderr
%64 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%65 = call i32 @fprintf(i32 %63, i8* %64, i8* %21)
br label %66
66: ; preds = %62, %36
%67 = load i32, i32* %9
%68 = call i32 @close(i32 %67)
br label %73
69: ; preds = %3
%70 = load i32, i32* @stderr
%71 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%72 = call i32 @fprintf(i32 %70, i8* %71, i8* %21)
br label %73
73: ; preds = %69, %66
%74 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
%struct.ypbind_resp = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32 }
@.str = [9 x i8] c"%s/%s.%u\00"
@O_RDONLY = global i32 0
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"Dump of %s:\0A\00"
@.str.2 = [14 x i8] c"\09Address: %s\0A\00"
@.str.3 = [11 x i8] c"\09Port: %i\0A\00"
@stderr = global i32 0
@.str.4 = [22 x i8] c"Error reading %s: %m\0A\00"
@.str.5 = [22 x i8] c"Error opening %s: %m\0A\00"
define void @dump_binding(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.ypbind_resp
%5 = alloca %struct.sockaddr_in
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = add nsw i64 %7, 23
%9 = alloca i8, i64 %8
%10 = trunc i64 %8 to i32
%11 = call i32 @snprintf(i8* %9, i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2)
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %9, i32 %12)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %43
15: ; preds = %3
%16 = bitcast %struct.ypbind_resp* %4 to i8*
%17 = call i32 @pread(i32 %13, %struct.ypbind_resp* %4, i32 8, i32 2)
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = load i32, i32* @INET_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
%24 = bitcast %struct.sockaddr_in* %5 to i8*
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.ypbind_resp, %struct.ypbind_resp* %4, i64 0, i32 0, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %28, i32* %29
%30 = call i32 @inet_ntop(i32 %25, i32* %29, i8* %23, i32 %20)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%33 = getelementptr inbounds %struct.ypbind_resp, %struct.ypbind_resp* %4, i64 0, i32 0, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @ntohs(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %41
37: ; preds = %15
%38 = load i32, i32* @stderr
%39 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @fprintf(i32 %38, i8* %39, i8* %9)
br label %41
41: ; preds = %37, %19
%42 = call i32 @close(i32 %13)
br label %47
43: ; preds = %3
%44 = load i32, i32* @stderr
%45 = call i8* @gettext(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @fprintf(i32 %44, i8* %45, i8* %9)
br label %47
47: ; preds = %43, %41
ret void
}