#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_family;
  int sin_port;
  int *sin_zero;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct hostent *gethostbyaddr(char *, int, int);
int ntohs(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, unsigned char,
                           unsigned char, unsigned char);
int sockio_dump_sockaddr(struct sockaddr_in *ptr, FILE *fp) {
  int i;
  unsigned char *uc;
  struct hostent *hp;
  char abuf[] = "xxx.xxx.xxx.xxx\0";
  fprintf(fp, "sin_family = %d\n", ptr->sin_family);
  fprintf(fp, "sin_port = %d (%d)\n", ptr->sin_port, ntohs(ptr->sin_port));
  uc = (unsigned char *)&ptr->sin_addr;
  sprintf(abuf, "%d.%d.%d.%d", uc[0], uc[1], uc[2], uc[3]);
  hp = gethostbyaddr((char *)&ptr->sin_addr.s_addr, sizeof(ptr->sin_addr),
                     ptr->sin_family);
  fprintf(fp, "sin_addr = %s (%s)\n", abuf, hp->h_name);
  for (i = 0; i < sizeof(struct sockaddr) - sizeof(short int) -
                      sizeof(unsigned short int) - sizeof(struct in_addr);
       i++) {
    fprintf(fp, "%x", ptr->sin_zero[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<sockio_dump_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea4(%rip),%al
mov    %al,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    %eax,%ecx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%r8b
mov    -0x20(%rbp),%rax
lea    0xe4a(%rip),%rsi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl 0x3(%rax),%r9d
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0xfffffffffffffffc,%rax
jae    127d <sockio_dump_sockaddr+0x13d>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1240 <sockio_dump_sockaddr+0x100>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockio_dump_sockaddr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movaps 0xea8(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    (%rdi),%edx
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x4(%r15),%ebx
mov    %ebx,%edi
call   1040 <ntohs@plt>
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0x10(%r15),%rbx
movzbl 0x10(%r15),%edx
movzbl 0x11(%r15),%ecx
movzbl 0x12(%r15),%r8d
movzbl 0x13(%r15),%r9d
lea    0xe83(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
call   1060 <sprintf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
mov    (%rax),%rcx
lea    0xe6a(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe6a(%rip),%r12
xor    %ebx,%ebx
xchg   %ax,%ax
mov    0x8(%r15),%rax
mov    (%rax,%rbx,1),%edx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x4,%rbx
jmp    11f0 <sockio_dump_sockaddr+0xb0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
@__const.sockio_dump_sockaddr.abuf = [17 x i8] c"xxx.xxx.xxx.xxx\00\00"
@.str = [17 x i8] c"sin_family = %d\0A\00"
@.str.1 = [20 x i8] c"sin_port = %d (%d)\0A\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
@.str.3 = [20 x i8] c"sin_addr = %s (%s)\0A\00"
@.str.4 = [3 x i8] c"%x\00"
define i32 @sockio_dump_sockaddr(%struct.sockaddr_in* %0, i32* %1) {
%3 = alloca %struct.sockaddr_in*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.hostent*
%8 = alloca [17 x i8]
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
store i32* %1, i32** %4
%9 = bitcast [17 x i8]* %8 to i8*
%10 = load i32*, i32** %4
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %4
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @ntohs(i32 %21)
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %22)
%24 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 3
%26 = bitcast %struct.TYPE_2__* %25 to i8*
store i8* %26, i8** %6
%27 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = load i8, i8* %38
%40 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %30, i8 zeroext %33, i8 zeroext %36, i8 zeroext %39)
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 3
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
%44 = bitcast i32* %43 to i8*
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call %struct.hostent* @gethostbyaddr(i8* %44, i32 4, i32 %47)
store %struct.hostent* %48, %struct.hostent** %7
%49 = load i32*, i32** %4
%50 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%51 = load %struct.hostent*, %struct.hostent** %7
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %53)
store i32 0, i32* %5
br label %55
55: ; preds = %69, %2
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = icmp ult i64 %57, -4
br i1 %58, label %59, label %72
59: ; preds = %55
%60 = load i32*, i32** %4
%61 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %61, i32 0, i32 2
%63 = load i32*, i32** %62
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %59
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
br label %55
72: ; preds = %55
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
@__const.sockio_dump_sockaddr.abuf = [17 x i8] c"xxx.xxx.xxx.xxx\00\00"
@.str = [17 x i8] c"sin_family = %d\0A\00"
@.str.1 = [20 x i8] c"sin_port = %d (%d)\0A\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
@.str.3 = [20 x i8] c"sin_addr = %s (%s)\0A\00"
@.str.4 = [3 x i8] c"%x\00"
define i32 @sockio_dump_sockaddr(%struct.sockaddr_in* %0, i32* nocapture %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%9 = load i32, i32* %8
%10 = tail call i32 @ntohs(i32 %9)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 3
%13 = bitcast %struct.TYPE_2__* %12 to i8*
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %13, i64 2
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %13, i64 3
%20 = load i8, i8* %19
%21 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %14, i8 zeroext %16, i8 zeroext %18, i8 zeroext %20)
%22 = load i32, i32* %5
%23 = tail call %struct.hostent* @gethostbyaddr(i8* %13, i32 4, i32 %22)
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
br label %28
28: ; preds = %28, %2
%29 = phi i64 [ %34, %28 ], [ 0, %2 ]
%30 = load i32*, i32** %27
%31 = getelementptr inbounds i32, i32* %30, i64 %29
%32 = load i32, i32* %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = add nuw i64 %29, 1
br label %28
}