#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 */

/* Variables and functions */
char *port_to_service(unsigned int, unsigned short);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
char *port_to_anyname(unsigned int port, unsigned short proto) {
  char *name;
  static char buf[10];
  if ((name = port_to_service(port, proto)) != NULL)
    return name;
  else {
    sprintf(buf, "%u", port);
    return buf;
  }
}


x86 assembly (clang, -O0):
<port_to_anyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0xc(%rbp),%edi
movzwl -0xe(%rbp),%esi
call   1030 <port_to_service@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1159 <port_to_anyname+0x39>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117a <port_to_anyname+0x5a>
mov    -0xc(%rbp),%edx
lea    0x2ece(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2ebb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<port_to_anyname>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <port_to_service@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    114a <port_to_anyname+0x2a>
lea    0x2ef8(%rip),%rbx
lea    0xec0(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@port_to_anyname.buf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @port_to_anyname(i32 %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
store i32 %0, i32* %4
store i16 %1, i16* %5
%7 = load i32, i32* %4
%8 = load i16, i16* %5
%9 = call i8* @port_to_service(i32 %7, i16 zeroext %8)
store i8* %9, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i8*, i8** %6
store i8* %12, i8** %3
br label %16
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @port_to_anyname.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @port_to_anyname.buf, i64 0, i64 0), i8** %3
br label %16
16: ; preds = %13, %11
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@port_to_anyname.buf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @port_to_anyname(i32 %0, i16 zeroext %1) {
%3 = tail call i8* @port_to_service(i32 %0, i16 zeroext %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @port_to_anyname.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %7
7: ; preds = %2, %5
%8 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @port_to_anyname.buf, i64 0, i64 0), %5 ], [ %3, %2 ]
ret i8* %8
}