#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 */
typedef int /*<<< orphan*/ u_char;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int MAXDNAME;
int dn_expand(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
              int /*<<< orphan*/ const *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
const u_char *p_cdnname(const u_char *cp, const u_char *msg, int len,
                        FILE *file) {
  char name[MAXDNAME];
  int n;
  if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
    return (NULL);
  if (name[0] == '\0')
    putc('.', file);
  else
    fputs(name, file);
  return (cp + n);
}


x86 assembly (clang, -O0):
<p_cdnname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rsi
mov    -0x10(%rbp),%rdx
mov    %eax,%r8d
call   1050 <dn_expand@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    11b2 <p_cdnname+0x82>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    11fc <p_cdnname+0xcc>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d5 <p_cdnname+0xa5>
mov    -0x28(%rbp),%rsi
mov    $0x2e,%edi
call   1040 <putc@plt>
jmp    11e2 <p_cdnname+0xb2>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <fputs@plt>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_cdnname>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rsi,%rax
mov    %rdi,%r15
mov    0x2e95(%rip),%rcx
mov    (%rcx),%r8d
mov    %rsp,%rbx
mov    %r8,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
movslq %edx,%rcx
lea    (%rsi,%rcx,4),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <dn_expand@plt>
test   %eax,%eax
js     1190 <p_cdnname+0x60>
mov    %eax,%r12d
cmpb   $0x0,(%rbx)
je     1194 <p_cdnname+0x64>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <fputs@plt>
jmp    11a1 <p_cdnname+0x71>
xor    %eax,%eax
jmp    11a8 <p_cdnname+0x78>
mov    $0x2e,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %r12d,%eax
lea    (%r15,%rax,4),%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXDNAME = global i32 0
define i32* @p_cdnname(i32* %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%14 = load i32, i32* @MAXDNAME
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i32*, i32** %7
%19 = load i32*, i32** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32*, i32** %6
%24 = trunc i64 %15 to i32
%25 = call i32 @dn_expand(i32* %18, i32* %22, i32* %23, i8* %17, i32 %24)
store i32 %25, i32* %12
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %4
store i32* null, i32** %5
store i32 1, i32* %13
br label %44
28: ; preds = %4
%29 = getelementptr inbounds i8, i8* %17, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32*, i32** %9
%35 = call i32 @putc(i8 signext 46, i32* %34)
br label %39
36: ; preds = %28
%37 = load i32*, i32** %9
%38 = call i32 @fputs(i8* %17, i32* %37)
br label %39
39: ; preds = %36, %33
%40 = load i32*, i32** %6
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32* %43, i32** %5
store i32 1, i32* %13
br label %44
44: ; preds = %39, %27
%45 = load i8*, i8** %10
%46 = load i32*, i32** %5
ret i32* %46
}

LLVM IR (-O2):
@MAXDNAME = global i32 0
define i32* @p_cdnname(i32* %0, i32* %1, i32 %2, i32* nocapture %3) {
%5 = load i32, i32* @MAXDNAME
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = call i32 @dn_expand(i32* %1, i32* %9, i32* %0, i8* %7, i32 %5)
%11 = icmp slt i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %4
%13 = load i8, i8* %7
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @putc(i8 signext 46, i32* %3)
br label %19
17: ; preds = %12
%18 = call i32 @fputs(i8* %7, i32* %3)
br label %19
19: ; preds = %17, %15
%20 = zext i32 %10 to i64
%21 = getelementptr inbounds i32, i32* %0, i64 %20
br label %22
22: ; preds = %4, %19
%23 = phi i32* [ %21, %19 ], [ null, %4 ]
ret i32* %23
}