#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 in_addr {
  int dummy;
};

/* Variables and functions */
char *addr_to_anyname(struct in_addr *);
char *inet_ntoa(struct in_addr);
char *malloc(int);
char *port_to_anyname(unsigned int, unsigned short);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
char *addrport_to_anyname(struct in_addr *addr, unsigned int port,
                          unsigned short proto, unsigned int format) {
  char *buf;
  if (!(buf = malloc(60)))
    return NULL;
  if (format & 0x0001) {
    snprintf(buf, 60, "%s:%u", inet_ntoa(*addr), port);
  } else {
    snprintf(buf, 60, "%s:%s", addr_to_anyname(addr),
             port_to_anyname(port, proto));
  }
  return buf;
}


x86 assembly (clang, -O0):
<addrport_to_anyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %ax,-0x16(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118e <addrport_to_anyname+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    121a <addrport_to_anyname+0xca>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d3 <addrport_to_anyname+0x83>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
mov    -0x14(%rbp),%r8d
mov    $0x3c,%esi
lea    0xe39(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1212 <addrport_to_anyname+0xc2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <addr_to_anyname@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
movzwl -0x16(%rbp),%esi
call   1040 <port_to_anyname@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
mov    $0x3c,%esi
lea    0xdfb(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addrport_to_anyname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
mov    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d5 <addrport_to_anyname+0x85>
test   $0x1,%bpl
jne    11b0 <addrport_to_anyname+0x60>
mov    %r12,%rdi
call   1060 <addr_to_anyname@plt>
mov    %rax,%rbp
movzwl %r15w,%esi
mov    %r14d,%edi
call   1040 <port_to_anyname@plt>
lea    0xe6d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3c,%esi
mov    %rbp,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11d5 <addrport_to_anyname+0x85>
mov    (%r12),%edi
call   1030 <inet_ntoa@plt>
lea    0xe40(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3c,%esi
mov    %rax,%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [6 x i8] c"%s:%u\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define i8* @addrport_to_anyname(%struct.in_addr* %0, i32 %1, i16 zeroext %2, i32 %3) {
%5 = alloca i8*
%6 = alloca %struct.in_addr*
%7 = alloca i32
%8 = alloca i16
%9 = alloca i32
%10 = alloca i8*
store %struct.in_addr* %0, %struct.in_addr** %6
store i32 %1, i32* %7
store i16 %2, i16* %8
store i32 %3, i32* %9
%11 = call i8* @malloc(i32 60)
store i8* %11, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %4
store i8* null, i8** %5
br label %36
14: ; preds = %4
%15 = load i32, i32* %9
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = load %struct.in_addr*, %struct.in_addr** %6
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i8* @inet_ntoa(i32 %22)
%24 = load i32, i32* %7
%25 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24)
br label %34
26: ; preds = %14
%27 = load i8*, i8** %10
%28 = load %struct.in_addr*, %struct.in_addr** %6
%29 = call i8* @addr_to_anyname(%struct.in_addr* %28)
%30 = load i32, i32* %7
%31 = load i16, i16* %8
%32 = call i8* @port_to_anyname(i32 %30, i16 zeroext %31)
%33 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %27, i32 60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %32)
br label %34
34: ; preds = %26, %18
%35 = load i8*, i8** %10
store i8* %35, i8** %5
br label %36
36: ; preds = %34, %13
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [6 x i8] c"%s:%u\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define i8* @addrport_to_anyname(%struct.in_addr* %0, i32 %1, i16 zeroext %2, i32 %3) {
%5 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = and i32 %3, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i8* @inet_ntoa(i32 %12)
%14 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %1)
br label %19
15: ; preds = %7
%16 = tail call i8* @addr_to_anyname(%struct.in_addr* %0)
%17 = tail call i8* @port_to_anyname(i32 %1, i16 zeroext %2)
%18 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
br label %19
19: ; preds = %10, %15, %4
ret i8* %5
}