#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 protoent {
  char *p_name;
};
typedef int __u8;

/* Variables and functions */
struct protoent *getprotobynumber(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *strxf_proto(__u8 proto) {
  static char buf[32];
  struct protoent *pp;
  const char *p;
  pp = getprotobynumber(proto);
  if (pp)
    p = pp->p_name;
  else {
    sprintf(buf, "%u", proto);
    p = buf;
  }
  return p;
}


x86 assembly (clang, -O0):
<strxf_proto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <getprotobynumber@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <strxf_proto+0x32>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1173 <strxf_proto+0x53>
mov    -0x4(%rbp),%edx
lea    0x2ee4(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2ed1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strxf_proto>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <getprotobynumber@plt>
test   %rax,%rax
je     1134 <strxf_proto+0x14>
mov    (%rax),%rbx
jmp    114c <strxf_proto+0x2c>
lea    0x2f05(%rip),%rbx
lea    0xebe(%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):
%struct.protoent = type { i8* }
@strxf_proto.buf = internal global [32 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @strxf_proto(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.protoent*
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call %struct.protoent* @getprotobynumber(i32 %5)
store %struct.protoent* %6, %struct.protoent** %3
%7 = load %struct.protoent*, %struct.protoent** %3
%8 = icmp ne %struct.protoent* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load %struct.protoent*, %struct.protoent** %3
%11 = getelementptr inbounds %struct.protoent, %struct.protoent* %10, i32 0, i32 0
%12 = load i8*, i8** %11
store i8* %12, i8** %4
br label %16
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @strxf_proto.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 ([32 x i8], [32 x i8]* @strxf_proto.buf, i64 0, i64 0), i8** %4
br label %16
16: ; preds = %13, %9
%17 = load i8*, i8** %4
ret i8* %17
}

LLVM IR (-O2):
%struct.protoent = type { i8* }
@strxf_proto.buf = internal global [32 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @strxf_proto(i32 %0) {
%2 = tail call %struct.protoent* @getprotobynumber(i32 %0)
%3 = icmp eq %struct.protoent* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.protoent, %struct.protoent* %2, i64 0, i32 0
%6 = load i8*, i8** %5
br label %9
7: ; preds = %1
%8 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @strxf_proto.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 %9
9: ; preds = %7, %4
%10 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @strxf_proto.buf, i64 0, i64 0), %7 ]
ret i8* %10
}