#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 *);
int 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 = 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     1198 <p_fqnname+0x68>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1174 <p_fqnname+0x44>
movslq %eax,%rcx
cmpb   $0x2e,-0x1(%rcx,%rbx,1)
je     1190 <p_fqnname+0x60>
lea    0x1(%rax),%ecx
cmp    %r15d,%ecx
jge    1198 <p_fqnname+0x68>
cltq
add    %rax,%rbx
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %ebp,%eax
lea    (%r14,%rax,4),%rax
jmp    119a <p_fqnname+0x6a>
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 %57
25: ; preds = %5
%26 = load i8*, i8** %10
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %13
%28 = load i32, i32* %13
%29 = icmp eq i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %25
%31 = load i8*, i8** %10
%32 = load i32, i32* %13
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 46
br i1 %38, label %39, label %52
39: ; preds = %30, %25
%40 = load i32, i32* %13
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %11
%43 = icmp sge i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %39
store i32* null, i32** %6
br label %57
45: ; preds = %39
%46 = load i8*, i8** %10
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %45
br label %52
52: ; preds = %51, %30
%53 = load i32*, i32** %7
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
store i32* %56, i32** %6
br label %57
57: ; preds = %52, %44, %24
%58 = load i32*, i32** %6
ret i32* %58
}

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 %29, label %10
10: ; preds = %5
%11 = tail call i32 @strlen(i8* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = add nsw i32 %11, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %26, label %19
19: ; preds = %13, %10
%20 = add nsw i32 %11, 1
%21 = icmp slt i32 %20, %4
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = sext i32 %11 to i64
%24 = getelementptr inbounds i8, i8* %3, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %22, %13
%27 = zext i32 %8 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
br label %29
29: ; preds = %19, %5, %26
%30 = phi i32* [ %28, %26 ], [ null, %5 ], [ null, %19 ]
ret i32* %30
}