#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__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ INADDR_BROADCAST;
int /*<<< orphan*/ NI_NUMERICHOST;
int getnameinfo(struct sockaddr *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int makeipaddr(struct sockaddr *addr, int addrlen, char *buf, int bufsize) {
  int error;
  if (addr->sa_family == AF_INET) {
    struct sockaddr_in *in = (struct sockaddr_in *)addr;
    if (in->sin_addr.s_addr == INADDR_BROADCAST) {
      if (strlen("<broadcast>") <= bufsize)
        strcpy(buf, "<broadcast>");
      return 0;
    }
  }
  error = getnameinfo(addr, addrlen, buf, bufsize, NULL, 0, NI_NUMERICHOST);
  if (error) {
    return error;
  }
  return 0;
}


x86 assembly (clang, -O0):
<makeipaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <makeipaddr+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <makeipaddr+0x7d>
lea    0xe7d(%rip),%rdi
call   1040 <strlen@plt>
cmp    -0x24(%rbp),%eax
jg     11a1 <makeipaddr+0x71>
mov    -0x20(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <makeipaddr+0xc6>
jmp    11b2 <makeipaddr+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11ef <makeipaddr+0xbf>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <makeipaddr+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeipaddr>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    (%rdi),%rax
mov    0x2ea6(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <makeipaddr+0x46>
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <makeipaddr+0x46>
lea    0xea6(%rip),%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jg     1172 <makeipaddr+0x42>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    1192 <makeipaddr+0x62>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rbx,%rdx
mov    %ebp,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <getnameinfo@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@AF_INET = global i64 0
@INADDR_BROADCAST = global i64 0
@.str = [12 x i8] c"<broadcast>\00"
@NI_NUMERICHOST = global i32 0
define i32 @makeipaddr(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in*
store %struct.sockaddr* %0, %struct.sockaddr** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load %struct.sockaddr*, %struct.sockaddr** %6
%13 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @AF_INET
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %4
%18 = load %struct.sockaddr*, %struct.sockaddr** %6
%19 = bitcast %struct.sockaddr* %18 to %struct.sockaddr_in*
store %struct.sockaddr_in* %19, %struct.sockaddr_in** %11
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* @INADDR_BROADCAST
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %17
%27 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* %9
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %8
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %30, %26
store i32 0, i32* %5
br label %47
34: ; preds = %17
br label %35
35: ; preds = %34, %4
%36 = load %struct.sockaddr*, %struct.sockaddr** %6
%37 = load i32, i32* %7
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = load i32, i32* @NI_NUMERICHOST
%41 = call i32 @getnameinfo(%struct.sockaddr* %36, i32 %37, i8* %38, i32 %39, i32* null, i32 0, i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = load i32, i32* %10
store i32 %45, i32* %5
br label %47
46: ; preds = %35
store i32 0, i32* %5
br label %47
47: ; preds = %46, %44, %33
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@INADDR_BROADCAST = global i64 0
@.str = [12 x i8] c"<broadcast>\00"
@NI_NUMERICHOST = global i32 0
define i32 @makeipaddr(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3) {
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @INADDR_BROADCAST
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = icmp sgt i32 %13, %3
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %4
%18 = load i32, i32* @NI_NUMERICHOST
%19 = tail call i32 @getnameinfo(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3, i32* null, i32 0, i32 %18)
br label %20
20: ; preds = %15, %12, %17
%21 = phi i32 [ %19, %17 ], [ 0, %12 ], [ 0, %15 ]
ret i32 %21
}