#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 */
int /*<<< orphan*/ free(char *);
size_t macro2len(int);
int /*<<< orphan*/ mandoc_asprintf(char **, char *, size_t);
int mdoc_hash_find(char *);
int /*<<< orphan*/ strcmp(char *, char *);
void rewrite_macro2len(char **arg) {
  size_t width;
  int tok;
  if (*arg == NULL)
    return;
  else if (!strcmp(*arg, "Ds"))
    width = 6;
  else if ((tok = mdoc_hash_find(*arg)) == (-1))
    return;
  else
    width = macro2len(tok);
  free(*arg);
  mandoc_asprintf(arg, "%zun", width);
}


x86 assembly (clang, -O0):
<rewrite_macro2len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116f <rewrite_macro2len+0x1f>
jmp    11eb <rewrite_macro2len+0x9b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1198 <rewrite_macro2len+0x48>
movq   $0x6,-0x10(%rbp)
jmp    11c6 <rewrite_macro2len+0x76>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <mdoc_hash_find@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11b5 <rewrite_macro2len+0x65>
jmp    11eb <rewrite_macro2len+0x9b>
mov    -0x14(%rbp),%edi
call   1070 <macro2len@plt>
mov    %rax,-0x10(%rbp)
jmp    11c6 <rewrite_macro2len+0x76>
jmp    11cb <rewrite_macro2len+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe1d(%rip),%rsi
call   1050 <mandoc_asprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_macro2len>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%rbx
test   %rbx,%rbx
je     118f <rewrite_macro2len+0x3f>
mov    %rdi,%r14
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1195 <rewrite_macro2len+0x45>
mov    %rbx,%rdi
call   1060 <mdoc_hash_find@plt>
cmp    $0xffffffff,%eax
je     118f <rewrite_macro2len+0x3f>
mov    %eax,%edi
call   1070 <macro2len@plt>
mov    %rax,%r15
mov    (%r14),%rbx
jmp    119b <rewrite_macro2len+0x4b>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x6,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <mandoc_asprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"Ds\00"
@.str.1 = [5 x i8] c"%zun\00"
define void @rewrite_macro2len(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i32
store i8** %0, i8*** %2
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
br label %33
9: ; preds = %1
%10 = load i8**, i8*** %2
%11 = load i8*, i8** %10
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
store i64 6, i64* %3
br label %25
15: ; preds = %9
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = call i32 @mdoc_hash_find(i8* %17)
store i32 %18, i32* %4
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %15
br label %33
21: ; preds = %15
%22 = load i32, i32* %4
%23 = call i64 @macro2len(i32 %22)
store i64 %23, i64* %3
br label %24
24: ; preds = %21
br label %25
25: ; preds = %24, %14
br label %26
26: ; preds = %25
%27 = load i8**, i8*** %2
%28 = load i8*, i8** %27
%29 = call i32 @free(i8* %28)
%30 = load i8**, i8*** %2
%31 = load i64, i64* %3
%32 = call i32 @mandoc_asprintf(i8** %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %31)
br label %33
33: ; preds = %26, %20, %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"Ds\00"
@.str.1 = [5 x i8] c"%zun\00"
define void @rewrite_macro2len(i8** %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @mdoc_hash_find(i8* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = tail call i64 @macro2len(i32 %8)
%12 = load i8*, i8** %0
br label %13
13: ; preds = %4, %10
%14 = phi i8* [ %12, %10 ], [ %2, %4 ]
%15 = phi i64 [ %11, %10 ], [ 6, %4 ]
%16 = tail call i32 @free(i8* %14)
%17 = tail call i32 @mandoc_asprintf(i8** %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %18
18: ; preds = %7, %1, %13
ret void
}