#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 confctl_var {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int asprintf(char **, char *, char const *, ...);
struct confctl_var *confctl_var_first_child(struct confctl_var *);
scalar_t__ confctl_var_has_children(struct confctl_var *);
scalar_t__ confctl_var_has_value(struct confctl_var *);
struct confctl_var *confctl_var_next(struct confctl_var *);
scalar_t__ cv_marked(struct confctl_var *);
char *cv_safe_name(struct confctl_var *);
char *cv_safe_value(struct confctl_var *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ free(char *);
void cv_print(struct confctl_var *cv, FILE *fp, const char *prefix,
              bool values_only) {
  struct confctl_var *child;
  char *newprefix, *name, *value;
  int written;
  if (cv_marked(cv))
    return;
  if (confctl_var_has_children(cv)) {
    name = cv_safe_name(cv);
    if (prefix != NULL)
      written = asprintf(&newprefix, "%s.%s", prefix, name);
    else
      written = asprintf(&newprefix, "%s", name);
    free(name);
    if (written < 0)
      err(1, "asprintf");
    for (child = confctl_var_first_child(cv); child != NULL;
         child = confctl_var_next(child))
      cv_print(child, fp, newprefix, values_only);
    free(newprefix);
  } else if (confctl_var_has_value(cv)) {
    value = cv_safe_value(cv);
    if (values_only) {
      fprintf(fp, "%s\n", value);
    } else {
      name = cv_safe_name(cv);
      if (prefix != NULL)
        fprintf(fp, "%s.%s=%s\n", prefix, name, value);
      else
        fprintf(fp, "%s=%s\n", name, value);
      free(name);
    }
    free(value);
  }
}


x86 assembly (clang, -O0):
<cv_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <cv_marked@plt>
cmp    $0x0,%rax
je     11ef <cv_print+0x2f>
jmp    1376 <cv_print+0x1b6>
mov    -0x8(%rbp),%rdi
call   10a0 <confctl_var_has_children@plt>
cmp    $0x0,%rax
je     12c5 <cv_print+0x105>
mov    -0x8(%rbp),%rdi
call   1050 <cv_safe_name@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123c <cv_print+0x7c>
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   10d0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
jmp    1255 <cv_print+0x95>
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   10d0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x44(%rbp)
jge    1279 <cv_print+0xb9>
mov    $0x1,%edi
lea    0xd92(%rip),%rsi
call   1090 <err@plt>
mov    -0x8(%rbp),%rdi
call   1040 <confctl_var_first_child@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12b7 <cv_print+0xf7>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1060 <cv_print@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <confctl_var_next@plt>
mov    %rax,-0x28(%rbp)
jmp    1286 <cv_print+0xc6>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1376 <cv_print+0x1b6>
mov    -0x8(%rbp),%rdi
call   10e0 <confctl_var_has_value@plt>
cmp    $0x0,%rax
je     1371 <cv_print+0x1b1>
mov    -0x8(%rbp),%rdi
call   10b0 <cv_safe_value@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     130a <cv_print+0x14a>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1368 <cv_print+0x1a8>
mov    -0x8(%rbp),%rdi
call   1050 <cv_safe_name@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1345 <cv_print+0x185>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    135f <cv_print+0x19f>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1376 <cv_print+0x1b6>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cv_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
call   1070 <cv_marked@plt>
test   %rax,%rax
jne    12ca <cv_print+0x10a>
mov    %r14,%rdi
call   10a0 <confctl_var_has_children@plt>
mov    %r14,%rdi
test   %rax,%rax
je     121a <cv_print+0x5a>
call   1050 <cv_safe_name@plt>
mov    %rax,%r12
test   %r15,%r15
je     1254 <cv_print+0x94>
lea    0xdf8(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   10d0 <asprintf@plt>
jmp    1268 <cv_print+0xa8>
call   10e0 <confctl_var_has_value@plt>
test   %rax,%rax
je     12ca <cv_print+0x10a>
mov    %r14,%rdi
call   10b0 <cv_safe_value@plt>
mov    %rax,%r12
test   %ebp,%ebp
je     12d9 <cv_print+0x119>
lea    0xdd3(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1324 <cv_print+0x164>
lea    0xda8(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   10d0 <asprintf@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
test   %ebx,%ebx
jns    1287 <cv_print+0xc7>
lea    0xd89(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    %r14,%rdi
call   1040 <confctl_var_first_child@plt>
test   %rax,%rax
je     12c1 <cv_print+0x101>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rdx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %ebp,%ecx
call   1060 <cv_print@plt>
mov    %rbx,%rdi
call   10c0 <confctl_var_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12a0 <cv_print+0xe0>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1050 <cv_safe_name@plt>
mov    %rax,%rbp
test   %r15,%r15
je     1305 <cv_print+0x145>
lea    0xd1f(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    131c <cv_print+0x15c>
lea    0xd06(%rip),%rsi
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.confctl_var = type { i32 }
@.str = [6 x i8] c"%s.%s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"asprintf\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [10 x i8] c"%s.%s=%s\0A\00"
@.str.5 = [7 x i8] c"%s=%s\0A\00"
define void @cv_print(%struct.confctl_var* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca %struct.confctl_var*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.confctl_var*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store %struct.confctl_var* %0, %struct.confctl_var** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load %struct.confctl_var*, %struct.confctl_var** %5
%15 = call i64 @cv_marked(%struct.confctl_var* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
br label %94
18: ; preds = %4
%19 = load %struct.confctl_var*, %struct.confctl_var** %5
%20 = call i64 @confctl_var_has_children(%struct.confctl_var* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %58
22: ; preds = %18
%23 = load %struct.confctl_var*, %struct.confctl_var** %5
%24 = call i8* @cv_safe_name(%struct.confctl_var* %23)
store i8* %24, i8** %11
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8*, i8** %11
%30 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
store i32 %30, i32* %13
br label %34
31: ; preds = %22
%32 = load i8*, i8** %11
%33 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 %33, i32* %13
br label %34
34: ; preds = %31, %27
%35 = load i8*, i8** %11
%36 = call i32 @free(i8* %35)
%37 = load i32, i32* %13
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = load %struct.confctl_var*, %struct.confctl_var** %5
%43 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %42)
store %struct.confctl_var* %43, %struct.confctl_var** %9
br label %44
44: ; preds = %52, %41
%45 = load %struct.confctl_var*, %struct.confctl_var** %9
%46 = icmp ne %struct.confctl_var* %45, null
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load %struct.confctl_var*, %struct.confctl_var** %9
%49 = load i32*, i32** %6
%50 = load i8*, i8** %10
%51 = load i32, i32* %8
br label %52
52: ; preds = %47
%53 = load %struct.confctl_var*, %struct.confctl_var** %9
%54 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %53)
store %struct.confctl_var* %54, %struct.confctl_var** %9
br label %44
55: ; preds = %44
%56 = load i8*, i8** %10
%57 = call i32 @free(i8* %56)
br label %94
58: ; preds = %18
%59 = load %struct.confctl_var*, %struct.confctl_var** %5
%60 = call i64 @confctl_var_has_value(%struct.confctl_var* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %93
62: ; preds = %58
%63 = load %struct.confctl_var*, %struct.confctl_var** %5
%64 = call i8* @cv_safe_value(%struct.confctl_var* %63)
store i8* %64, i8** %12
%65 = load i32, i32* %8
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = load i32*, i32** %6
%69 = load i8*, i8** %12
%70 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %90
71: ; preds = %62
%72 = load %struct.confctl_var*, %struct.confctl_var** %5
%73 = call i8* @cv_safe_name(%struct.confctl_var* %72)
store i8* %73, i8** %11
%74 = load i8*, i8** %7
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %82
76: ; preds = %71
%77 = load i32*, i32** %6
%78 = load i8*, i8** %7
%79 = load i8*, i8** %11
%80 = load i8*, i8** %12
%81 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %78, i8* %79, i8* %80)
br label %87
82: ; preds = %71
%83 = load i32*, i32** %6
%84 = load i8*, i8** %11
%85 = load i8*, i8** %12
%86 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %84, i8* %85)
br label %87
87: ; preds = %82, %76
%88 = load i8*, i8** %11
%89 = call i32 @free(i8* %88)
br label %90
90: ; preds = %87, %67
%91 = load i8*, i8** %12
%92 = call i32 @free(i8* %91)
br label %93
93: ; preds = %90, %58
br label %94
94: ; preds = %17, %93, %55
ret void
}

LLVM IR (-O2):
%struct.confctl_var = type { i32 }
@.str = [6 x i8] c"%s.%s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"asprintf\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [10 x i8] c"%s.%s=%s\0A\00"
@.str.5 = [7 x i8] c"%s=%s\0A\00"
define void @cv_print(%struct.confctl_var* %0, i32* nocapture %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = tail call i64 @cv_marked(%struct.confctl_var* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %55
9: ; preds = %4
%10 = tail call i64 @confctl_var_has_children(%struct.confctl_var* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %36, label %12
12: ; preds = %9
%13 = tail call i8* @cv_safe_name(%struct.confctl_var* %0)
%14 = icmp eq i8* %2, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %13)
br label %19
17: ; preds = %12
%18 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
%21 = call i32 @free(i8* %13)
%22 = icmp slt i32 %20, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %0)
%27 = icmp eq %struct.confctl_var* %26, null
br i1 %27, label %33, label %28
28: ; preds = %25, %28
%29 = phi %struct.confctl_var* [ %31, %28 ], [ %26, %25 ]
%30 = load i8*, i8** %5
%31 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %29)
%32 = icmp eq %struct.confctl_var* %31, null
br i1 %32, label %33, label %28
33: ; preds = %28, %25
%34 = load i8*, i8** %5
%35 = call i32 @free(i8* %34)
br label %55
36: ; preds = %9
%37 = tail call i64 @confctl_var_has_value(%struct.confctl_var* %0)
%38 = icmp eq i64 %37, 0
br i1 %38, label %55, label %39
39: ; preds = %36
%40 = tail call i8* @cv_safe_value(%struct.confctl_var* %0)
%41 = icmp eq i32 %3, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %53
44: ; preds = %39
%45 = tail call i8* @cv_safe_name(%struct.confctl_var* %0)
%46 = icmp eq i8* %2, null
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %45, i8* %40)
br label %51
49: ; preds = %44
%50 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %45, i8* %40)
br label %51
51: ; preds = %49, %47
%52 = tail call i32 @free(i8* %45)
br label %53
53: ; preds = %51, %42
%54 = tail call i32 @free(i8* %40)
br label %55
55: ; preds = %33, %53, %36, %4
ret void
}