#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 {
  int dummy;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int getnameinfo(struct sockaddr *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void getHost(char *name, char *ip) {
  struct sockaddr sa;
  int ret = getnameinfo(&sa, sizeof(sa), name, 64, NULL, 0, 0);
  if (ret) {
    snprintf(name, 64, "%s", "Cannot resolve name.");
  }
}


x86 assembly (clang, -O0):
<getHost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x40,%ecx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   1040 <getnameinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117f <getHost+0x5f>
mov    -0x8(%rbp),%rdi
mov    $0x40,%esi
lea    0xe8d(%rip),%rdx
lea    0xe89(%rip),%rcx
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHost>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
mov    $0x40,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <getnameinfo@plt>
test   %eax,%eax
je     116b <getHost+0x4b>
lea    0xea9(%rip),%rdx
lea    0xea5(%rip),%rcx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Cannot resolve name.\00"
define void @getHost(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sockaddr
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @getnameinfo(%struct.sockaddr* %5, i32 4, i8* %7, i32 64, i32* null, i32 0, i32 0)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @snprintf(i8* %12, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Cannot resolve name.\00"
define void @getHost(i8* %0, i8* nocapture readnone %1) {
%3 = alloca %struct.sockaddr
%4 = bitcast %struct.sockaddr* %3 to i8*
%5 = call i32 @getnameinfo(%struct.sockaddr* %3, i32 4, i8* %0, i32 64, i32* null, i32 0, i32 0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @snprintf(i8* %0, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
ret void
}