#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;

/* Variables and functions */
int dn_expand(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
              int /*<<< orphan*/ const *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
const u_char *p_fqnname(const u_char *cp, const u_char *msg, int msglen,
                        char *name, int namelen) {
  int n, newlen;
  if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
    return (NULL);
  newlen = (int)strlen(name);
  if (newlen == 0 || name[newlen - 1] != '.') {
    if (newlen + 1 >= namelen)
      return (NULL);
    else
      strcpy(name + newlen, ".");
  }
  return (cp + n);
}


x86 assembly (clang, -O0):
<p_fqnname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1050 <dn_expand@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1188 <p_fqnname+0x58>
movq   $0x0,-0x8(%rbp)
jmp    1203 <p_fqnname+0xd3>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11b8 <p_fqnname+0x88>
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11f0 <p_fqnname+0xc0>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cmp    -0x2c(%rbp),%eax
jl     11d4 <p_fqnname+0xa4>
movq   $0x0,-0x8(%rbp)
jmp    1203 <p_fqnname+0xd3>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    0xe1a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f0 <p_fqnname+0xc0>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_fqnname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
movslq %edx,%rcx
lea    (%rdi,%rcx,4),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <dn_expand@plt>
test   %eax,%eax
js     119c <p_fqnname+0x6c>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
test   %eax,%eax
je     1178 <p_fqnname+0x48>
lea    -0x1(%rax),%edx
movslq %edx,%rdx
cmpb   $0x2e,(%rbx,%rdx,1)
je     1194 <p_fqnname+0x64>
add    $0x1,%ecx
cmp    %r15d,%ecx
jge    119c <p_fqnname+0x6c>
cltq
add    %rax,%rbx
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %ebp,%eax
lea    (%r14,%rax,4),%rax
jmp    119e <p_fqnname+0x6e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32* @p_fqnname(i32* %0, i32* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i32*, i32** %8
%15 = load i32*, i32** %7
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32*, i32** %7
%20 = load i8*, i8** %10
%21 = load i32, i32* %11
%22 = call i32 @dn_expand(i32* %14, i32* %18, i32* %19, i8* %20, i32 %21)
store i32 %22, i32* %12
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %5
store i32* null, i32** %6
br label %58
25: ; preds = %5
%26 = load i8*, i8** %10
%27 = call i64 @strlen(i8* %26)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %13
%29 = load i32, i32* %13
%30 = icmp eq i32 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %25
%32 = load i8*, i8** %10
%33 = load i32, i32* %13
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 46
br i1 %39, label %40, label %53
40: ; preds = %31, %25
%41 = load i32, i32* %13
%42 = add nsw i32 %41, 1
%43 = load i32, i32* %11
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %40
store i32* null, i32** %6
br label %58
46: ; preds = %40
%47 = load i8*, i8** %10
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %46
br label %53
53: ; preds = %52, %31
%54 = load i32*, i32** %7
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32* %57, i32** %6
br label %58
58: ; preds = %53, %45, %24
%59 = load i32*, i32** %6
ret i32* %59
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32* @p_fqnname(i32* %0, i32* %1, i32 %2, i8* %3, i32 %4) {
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = tail call i32 @dn_expand(i32* %1, i32* %7, i32* %0, i8* %3, i32 %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %5
%11 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%12 = trunc i64 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = shl i64 %11, 32
%16 = add i64 %15, -4294967296
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %3, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 46
br i1 %20, label %29, label %21
21: ; preds = %14, %10
%22 = add nsw i32 %12, 1
%23 = icmp slt i32 %22, %4
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = shl i64 %11, 32
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds i8, i8* %3, i64 %26
%28 = tail call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %24, %14
%30 = zext i32 %8 to i64
%31 = getelementptr inbounds i32, i32* %0, i64 %30
br label %32
32: ; preds = %21, %5, %29
%33 = phi i32* [ %31, %29 ], [ null, %5 ], [ null, %21 ]
ret i32* %33
}