#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ error_quit(char *);
int /*<<< orphan*/ *inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
char *sock_ntop_host(const struct sockaddr *sa, socklen_t salen) {
  static char str[128];
  struct sockaddr_in *sin = (struct sockaddr_in *)sa;
  if (sa->sa_family != AF_INET)
    error_quit("sock_ntop_host: the type must be AF_INET");
  if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL)
    error_quit("inet_ntop error");
  return str;
}


x86 assembly (clang, -O0):
<sock_ntop_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%rax
je     115a <sock_ntop_host+0x3a>
lea    0xeab(%rip),%rdi
call   1040 <error_quit@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
lea    0x2ed1(%rip),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    118f <sock_ntop_host+0x6f>
lea    0xe9f(%rip),%rdi
call   1040 <error_quit@plt>
lea    0x2eaa(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_ntop_host>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    0x2eb7(%rip),%r14
cmp    (%r14),%rdi
je     1145 <sock_ntop_host+0x25>
lea    0xec3(%rip),%rdi
call   1040 <error_quit@plt>
mov    (%r14),%rdi
lea    0x2ef4(%rip),%rdx
mov    %rbx,%rsi
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
jne    116a <sock_ntop_host+0x4a>
lea    0xec4(%rip),%rdi
call   1040 <error_quit@plt>
lea    0x2ecf(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32 }
@sock_ntop_host.str = internal global [128 x i8] zeroinitializer
@AF_INET = global i64 0
@.str = [41 x i8] c"sock_ntop_host: the type must be AF_INET\00"
@.str.1 = [16 x i8] c"inet_ntop error\00"
define i8* @sock_ntop_host(%struct.sockaddr* %0, i32 %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i32 %1, i32* %4
%6 = load %struct.sockaddr*, %struct.sockaddr** %3
%7 = bitcast %struct.sockaddr* %6 to %struct.sockaddr_in*
store %struct.sockaddr_in* %7, %struct.sockaddr_in** %5
%8 = load %struct.sockaddr*, %struct.sockaddr** %3
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @AF_INET
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @error_quit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i64, i64* @AF_INET
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = call i32* @inet_ntop(i64 %16, i32* %18, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sock_ntop_host.str, i64 0, i64 0), i32 128)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @error_quit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sock_ntop_host.str, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@sock_ntop_host.str = internal global [128 x i8] zeroinitializer
@AF_INET = global i64 0
@.str = [41 x i8] c"sock_ntop_host: the type must be AF_INET\00"
@.str.1 = [16 x i8] c"inet_ntop error\00"
define i8* @sock_ntop_host(%struct.sockaddr* %0, i32 %1) {
%3 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @AF_INET
%6 = icmp eq i64 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @error_quit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = load i64, i64* @AF_INET
br label %10
10: ; preds = %7, %2
%11 = phi i64 [ %9, %7 ], [ %4, %2 ]
%12 = bitcast %struct.sockaddr* %0 to i32*
%13 = tail call i32* @inet_ntop(i64 %11, i32* %12, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sock_ntop_host.str, i64 0, i64 0), i32 128)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @error_quit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @sock_ntop_host.str, i64 0, i64 0)
}