#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 growing_keyvals {
  int dummy;
};

/* Variables and functions */
int comments_add_const(struct growing_keyvals *, char *, char *);
char *fix_key(char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ keyvals_add(struct growing_keyvals *, char const *, char *);
scalar_t__ keyvals_get_val_growing(struct growing_keyvals *, char const *);
int /*<<< orphan*/ strcasecmp(char const *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
int comments_add(struct growing_keyvals *c, const char *key, char *val) {
  if (!strcasecmp(key, "songwriter")) {
    int r = comments_add_const(c, "lyricist", val);
    return comments_add(c, "composer", val) && r;
  }
  key = fix_key(key);
  if (!key) {
    free(val);
    return 0;
  }
  if (!strcmp(key, "tracknumber") || !strcmp(key, "discnumber")) {
    char *slash = strchr(val, '/');
    if (slash)
      *slash = 0;
  }
  if (keyvals_get_val_growing(c, key)) {
    free(val);
    return 0;
  }
  keyvals_add(c, key, val);
  return 1;
}


x86 assembly (clang, -O0):
<comments_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1212 <comments_add+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1080 <comments_add_const@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe31(%rip),%rsi
call   10b0 <comments_add@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     1202 <comments_add+0x72>
cmpl   $0x0,-0x24(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    12de <comments_add+0x14e>
mov    -0x18(%rbp),%rdi
call   10a0 <fix_key@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123f <comments_add+0xaf>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <comments_add+0x14e>
mov    -0x18(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1271 <comments_add+0xe1>
mov    -0x18(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    129a <comments_add+0x10a>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1295 <comments_add+0x105>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    129a <comments_add+0x10a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <keyvals_get_val_growing@plt>
cmp    $0x0,%rax
je     12c6 <comments_add+0x136>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <comments_add+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <keyvals_add@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comments_add>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1218 <comments_add+0x88>
mov    %rbx,%rdi
call   10a0 <fix_key@plt>
test   %rax,%rax
je     120c <comments_add+0x7c>
mov    %rax,%rbx
lea    0xe55(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11e7 <comments_add+0x57>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11fc <comments_add+0x6c>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11fc <comments_add+0x6c>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <keyvals_get_val_growing@plt>
test   %rax,%rax
je     124f <comments_add+0xbf>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1262 <comments_add+0xd2>
lea    0xdec(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1080 <comments_add_const@plt>
mov    %eax,%ebx
lea    0xde1(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   10b0 <comments_add@plt>
test   %eax,%eax
setne  %al
test   %ebx,%ebx
setne  %cl
and    %al,%cl
movzbl %cl,%eax
jmp    1262 <comments_add+0xd2>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <keyvals_add@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.growing_keyvals = type { i32 }
@.str = [11 x i8] c"songwriter\00"
@.str.1 = [9 x i8] c"lyricist\00"
@.str.2 = [9 x i8] c"composer\00"
@.str.3 = [12 x i8] c"tracknumber\00"
@.str.4 = [11 x i8] c"discnumber\00"
define i32 @comments_add(%struct.growing_keyvals* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.growing_keyvals*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store %struct.growing_keyvals* %0, %struct.growing_keyvals** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %6
%11 = call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %3
%14 = load %struct.growing_keyvals*, %struct.growing_keyvals** %5
%15 = load i8*, i8** %7
%16 = call i32 @comments_add_const(%struct.growing_keyvals* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 %16, i32* %8
%17 = load %struct.growing_keyvals*, %struct.growing_keyvals** %5
%18 = load i8*, i8** %7
%19 = call i32 @comments_add(%struct.growing_keyvals* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %21, %13
%25 = phi i1 [ false, %13 ], [ %23, %21 ]
%26 = zext i1 %25 to i32
store i32 %26, i32* %4
br label %64
27: ; preds = %3
%28 = load i8*, i8** %6
%29 = call i8* @fix_key(i8* %28)
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
store i32 0, i32* %4
br label %64
35: ; preds = %27
%36 = load i8*, i8** %6
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %51, label %43
43: ; preds = %39, %35
%44 = load i8*, i8** %7
%45 = call i8* @strchr(i8* %44, i8 signext 47)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %9
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43
br label %51
51: ; preds = %50, %39
%52 = load %struct.growing_keyvals*, %struct.growing_keyvals** %5
%53 = load i8*, i8** %6
%54 = call i64 @keyvals_get_val_growing(%struct.growing_keyvals* %52, i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = call i32 @free(i8* %57)
store i32 0, i32* %4
br label %64
59: ; preds = %51
%60 = load %struct.growing_keyvals*, %struct.growing_keyvals** %5
%61 = load i8*, i8** %6
%62 = load i8*, i8** %7
%63 = call i32 @keyvals_add(%struct.growing_keyvals* %60, i8* %61, i8* %62)
store i32 1, i32* %4
br label %64
64: ; preds = %59, %56, %32, %24
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
%struct.growing_keyvals = type { i32 }
@.str = [11 x i8] c"songwriter\00"
@.str.1 = [9 x i8] c"lyricist\00"
@.str.2 = [9 x i8] c"composer\00"
@.str.3 = [12 x i8] c"tracknumber\00"
@.str.4 = [11 x i8] c"discnumber\00"
define i32 @comments_add(%struct.growing_keyvals* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strcasecmp(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %15
6: ; preds = %18, %33, %35, %8
%7 = phi i32 [ %14, %8 ], [ 0, %33 ], [ 1, %35 ], [ 0, %18 ]
ret i32 %7
8: ; preds = %3
%9 = tail call i32 @comments_add_const(%struct.growing_keyvals* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%10 = tail call i32 @comments_add(%struct.growing_keyvals* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = icmp ne i32 %10, 0
%12 = icmp ne i32 %9, 0
%13 = select i1 %11, i1 %12, i1 false
%14 = zext i1 %13 to i32
br label %6
15: ; preds = %3
%16 = tail call i8* @fix_key(i8* %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @free(i8* %2)
br label %6
20: ; preds = %15
%21 = tail call i32 @strcmp(i8* %16, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @strcmp(i8* %16, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23, %20
%27 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 47)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i8 0, i8* %27
br label %30
30: ; preds = %26, %29, %23
%31 = tail call i64 @keyvals_get_val_growing(%struct.growing_keyvals* %0, i8* %16)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @free(i8* %2)
br label %6
35: ; preds = %30
%36 = tail call i32 @keyvals_add(%struct.growing_keyvals* %0, i8* %16, i8* %2)
br label %6
}