#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 */
typedef int uint8_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};
typedef scalar_t__ sa_family_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int Gleep(int /*<<< orphan*/ *, char *);
scalar_t__ PF_INET;
scalar_t__ PF_INET6;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int ntohs(int /*<<< orphan*/);
extern int SH_PrintSockAddr(FILE *f, struct sockaddr *sap) {
  sa_family_t fam = sap->sa_family;
  if (fam == PF_INET) {
    struct sockaddr_in *sa4 = (struct sockaddr_in *)sap;
    uint8_t *p = (uint8_t *)&sa4->sin_addr;
    fprintf(f, "%d.%d.%d.%d:%d", p[0] & 255, p[1] & 255, p[2] & 255, p[3] & 255,
            ntohs(sa4->sin_port));
  } else if (fam == PF_INET6) {
    struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sap;
    uint8_t *p = (uint8_t *)&sa6->sin6_addr;
    int i = 0;
    for (; i < 16; i++) {
      uint8_t b = p[i];
      if (i > 0)
        fprintf(f, ":");
      if (b != 0)
        fprintf(f, "%x", b);
    }
    fprintf(f, "!%d", ntohs(sa6->sin6_port));
  } else {
    return Gleep(f, "SH_PrintSockAddr");
  }
  return 0;
}


x86 assembly (clang, -O0):
<SH_PrintSockAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
jne    11e9 <SH_PrintSockAddr+0xb9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
and    $0xff,%eax
mov    %eax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%eax
and    $0xff,%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%eax
and    $0xff,%eax
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%eax
and    $0xff,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%edx
mov    -0x54(%rbp),%ecx
mov    -0x50(%rbp),%r8d
mov    -0x4c(%rbp),%r9d
lea    0xe26(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12c7 <SH_PrintSockAddr+0x197>
mov    -0x20(%rbp),%rax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
jne    12aa <SH_PrintSockAddr+0x17a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x10,-0x44(%rbp)
jge    127e <SH_PrintSockAddr+0x14e>
mov    -0x40(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    124c <SH_PrintSockAddr+0x11c>
mov    -0x10(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x48(%rbp)
je     126b <SH_PrintSockAddr+0x13b>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%edx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1270 <SH_PrintSockAddr+0x140>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1218 <SH_PrintSockAddr+0xe8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12c2 <SH_PrintSockAddr+0x192>
mov    -0x10(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1050 <Gleep@plt>
mov    %eax,-0x4(%rbp)
jmp    12ce <SH_PrintSockAddr+0x19e>
jmp    12c7 <SH_PrintSockAddr+0x197>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SH_PrintSockAddr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
mov    (%rsi),%rdi
mov    0x2e7d(%rip),%rax
mov    %rdi,%rdx
shr    $0x20,%rdx
cmp    (%rax),%rdi
jne    11a2 <SH_PrintSockAddr+0x62>
movzbl %dl,%ebp
movzbl 0x8(%r14),%r15d
movzbl 0xc(%r14),%r12d
movzbl 0x10(%r14),%r14d
call   1050 <ntohs@plt>
mov    %eax,(%rsp)
lea    0xe78(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1239 <SH_PrintSockAddr+0xf9>
mov    0x2e3f(%rip),%rax
cmp    (%rax),%rdi
jne    1201 <SH_PrintSockAddr+0xc1>
test   %edx,%edx
je     11c3 <SH_PrintSockAddr+0x83>
lea    0xe56(%rip),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe45(%rip),%r15
xor    %ebx,%ebx
jmp    11da <SH_PrintSockAddr+0x9a>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0xf,%rbx
je     121e <SH_PrintSockAddr+0xde>
mov    0x8(%r14,%rbx,4),%ebp
mov    $0x3a,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
test   %ebp,%ebp
je     11d0 <SH_PrintSockAddr+0x90>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d0 <SH_PrintSockAddr+0x90>
lea    0xe0e(%rip),%rsi
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <Gleep@plt>
mov    (%r14),%edi
call   1050 <ntohs@plt>
lea    0xde5(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
@PF_INET = global i64 0
@.str = [15 x i8] c"%d.%d.%d.%d:%d\00"
@PF_INET6 = global i64 0
@.str.1 = [2 x i8] c":\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [4 x i8] c"!%d\00"
@.str.4 = [17 x i8] c"SH_PrintSockAddr\00"
define i32 @SH_PrintSockAddr(i32* %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.sockaddr*
%6 = alloca i64
%7 = alloca %struct.sockaddr_in*
%8 = alloca i32*
%9 = alloca %struct.sockaddr_in6*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%13 = load %struct.sockaddr*, %struct.sockaddr** %5
%14 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %13, i32 0, i32 0
%15 = load i64, i64* %14
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = load i64, i64* @PF_INET
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %46
19: ; preds = %2
%20 = load %struct.sockaddr*, %struct.sockaddr** %5
%21 = bitcast %struct.sockaddr* %20 to %struct.sockaddr_in*
store %struct.sockaddr_in* %21, %struct.sockaddr_in** %7
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 1
store i32* %23, i32** %8
%24 = load i32*, i32** %4
%25 = load i32*, i32** %8
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = and i32 %27, 255
%29 = load i32*, i32** %8
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = and i32 %31, 255
%33 = load i32*, i32** %8
%34 = getelementptr inbounds i32, i32* %33, i64 2
%35 = load i32, i32* %34
%36 = and i32 %35, 255
%37 = load i32*, i32** %8
%38 = getelementptr inbounds i32, i32* %37, i64 3
%39 = load i32, i32* %38
%40 = and i32 %39, 255
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @ntohs(i32 %43)
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %32, i32 %36, i32 %40, i32 %44)
br label %91
46: ; preds = %2
%47 = load i64, i64* %6
%48 = load i64, i64* @PF_INET6
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %87
50: ; preds = %46
%51 = load %struct.sockaddr*, %struct.sockaddr** %5
%52 = bitcast %struct.sockaddr* %51 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %52, %struct.sockaddr_in6** %9
%53 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%54 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %53, i32 0, i32 1
store i32* %54, i32** %10
store i32 0, i32* %11
br label %55
55: ; preds = %77, %50
%56 = load i32, i32* %11
%57 = icmp slt i32 %56, 16
br i1 %57, label %58, label %80
58: ; preds = %55
%59 = load i32*, i32** %10
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
store i32 %63, i32* %12
%64 = load i32, i32* %11
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %58
%67 = load i32*, i32** %4
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %66, %58
%70 = load i32, i32* %12
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32*, i32** %4
%74 = load i32, i32* %12
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %72, %69
br label %77
77: ; preds = %76
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %55
80: ; preds = %55
%81 = load i32*, i32** %4
%82 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%83 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @ntohs(i32 %84)
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %85)
br label %90
87: ; preds = %46
%88 = load i32*, i32** %4
%89 = call i32 @Gleep(i32* %88, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 %89, i32* %3
br label %92
90: ; preds = %80
br label %91
91: ; preds = %90, %19
store i32 0, i32* %3
br label %92
92: ; preds = %91, %87
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
@PF_INET = global i64 0
@.str = [15 x i8] c"%d.%d.%d.%d:%d\00"
@PF_INET6 = global i64 0
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [4 x i8] c"!%d\00"
@.str.4 = [17 x i8] c"SH_PrintSockAddr\00"
define i32 @SH_PrintSockAddr(i32* %0, %struct.sockaddr* nocapture %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @PF_INET
%6 = icmp eq i64 %4, %5
%7 = lshr i64 %4, 32
%8 = trunc i64 %7 to i32
br i1 %6, label %9, label %25
9: ; preds = %2
%10 = trunc i64 %4 to i32
%11 = bitcast %struct.sockaddr* %1 to %struct.sockaddr_in*
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i64 0, i32 1
%13 = and i32 %8, 255
%14 = getelementptr inbounds i32, i32* %12, i64 1
%15 = load i32, i32* %14
%16 = and i32 %15, 255
%17 = getelementptr inbounds i32, i32* %12, i64 2
%18 = load i32, i32* %17
%19 = and i32 %18, 255
%20 = getelementptr inbounds i32, i32* %12, i64 3
%21 = load i32, i32* %20
%22 = and i32 %21, 255
%23 = tail call i32 @ntohs(i32 %10)
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22, i32 %23)
br label %53
25: ; preds = %2
%26 = load i64, i64* @PF_INET6
%27 = icmp eq i64 %4, %26
br i1 %27, label %28, label %51
28: ; preds = %25
%29 = bitcast %struct.sockaddr* %1 to %struct.sockaddr_in6*
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %29, i64 0, i32 1
%31 = icmp eq i32 %8, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %34
34: ; preds = %28, %32
br label %35
35: ; preds = %34, %43
%36 = phi i64 [ %44, %43 ], [ 1, %34 ]
%37 = getelementptr inbounds i32, i32* %30, i64 %36
%38 = load i32, i32* %37
%39 = tail call i32 @fputc(i32 58, i32* %0)
%40 = icmp eq i32 %38, 0
br i1 %40, label %43, label %41
41: ; preds = %35
%42 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %43
43: ; preds = %41, %35
%44 = add nuw nsw i64 %36, 1
%45 = icmp eq i64 %44, 16
br i1 %45, label %46, label %35
46: ; preds = %43
%47 = bitcast %struct.sockaddr* %1 to i32*
%48 = load i32, i32* %47
%49 = tail call i32 @ntohs(i32 %48)
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %53
51: ; preds = %25
%52 = tail call i32 @Gleep(i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %9, %46, %51
%54 = phi i32 [ %52, %51 ], [ 0, %46 ], [ 0, %9 ]
ret i32 %54
}