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

/* Variables and functions */
int /*<<< orphan*/ attr_set_str_key(struct attrset **, char *, char *, int);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char const *);
void text_add_attrs(struct attrset **attrs, const char *new, int o) {
  char sep = *new ++;
  char *cpy = strdup(new);
  char *a = cpy;
  while (a) {
    char *k, *v;
    k = a;
    a = strchr(a, sep);
    if (a)
      *a++ = '\0';
    v = strchr(k, '=');
    if (v)
      *v++ = '\0';
    else
      continue;
    attr_set_str_key(attrs, k, v, o);
  }
  free(cpy);
}


x86 assembly (clang, -O0):
<text_add_attrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120f <text_add_attrs+0xcf>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bd <text_add_attrs+0x7d>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11f1 <text_add_attrs+0xb1>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
jmp    11f6 <text_add_attrs+0xb6>
jmp    117c <text_add_attrs+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1050 <attr_set_str_key@plt>
jmp    117c <text_add_attrs+0x3c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_add_attrs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r12
mov    (%rsi),%bl
lea    0x1(%rsi),%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ce <text_add_attrs+0x8e>
movsbl %bl,%r13d
mov    %r14,%rbx
jmp    1178 <text_add_attrs+0x38>
nopl   (%rax)
mov    %rbp,%rbx
test   %rbp,%rbp
je     11ce <text_add_attrs+0x8e>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a0 <text_add_attrs+0x60>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
jmp    11a2 <text_add_attrs+0x62>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <text_add_attrs+0x30>
mov    %rax,%rdx
add    $0x1,%rdx
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15d,%ecx
call   1050 <attr_set_str_key@plt>
jmp    1170 <text_add_attrs+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.attrset = type { i32 }
define void @text_add_attrs(%struct.attrset** %0, i8* %1, i32 %2) {
%4 = alloca %struct.attrset**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store %struct.attrset** %0, %struct.attrset*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
store i8 %14, i8* %7
%15 = load i8*, i8** %5
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
store i8* %17, i8** %9
br label %18
18: ; preds = %40, %39, %3
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %46
21: ; preds = %18
%22 = load i8*, i8** %9
store i8* %22, i8** %10
%23 = load i8*, i8** %9
%24 = load i8, i8* %7
%25 = call i8* @strchr(i8* %23, i8 signext %24)
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %9
store i8 0, i8* %29
br label %31
31: ; preds = %28, %21
%32 = load i8*, i8** %10
%33 = call i8* @strchr(i8* %32, i8 signext 61)
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %11
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %11
store i8 0, i8* %37
br label %40
39: ; preds = %31
br label %18
40: ; preds = %36
%41 = load %struct.attrset**, %struct.attrset*** %4
%42 = load i8*, i8** %10
%43 = load i8*, i8** %11
%44 = load i32, i32* %6
%45 = call i32 @attr_set_str_key(%struct.attrset** %41, i8* %42, i8* %43, i32 %44)
br label %18
46: ; preds = %18
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
ret void
}

LLVM IR (-O2):
%struct.attrset = type { i32 }
define void @text_add_attrs(%struct.attrset** %0, i8* nocapture %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = load i8, i8* %1
%6 = tail call i8* @strdup(i8* %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %3, %21
%9 = phi i8* [ %15, %21 ], [ %6, %3 ]
%10 = tail call i8* @strchr(i8* %9, i8 signext %5)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %10, i64 1
store i8 0, i8* %10
br label %14
14: ; preds = %12, %8
%15 = phi i8* [ %13, %12 ], [ null, %8 ]
%16 = tail call i8* @strchr(i8* %9, i8 signext 61)
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %16, i64 1
store i8 0, i8* %16
%20 = tail call i32 @attr_set_str_key(%struct.attrset** %0, i8* %9, i8* %19, i32 %2)
br label %21
21: ; preds = %14, %18
%22 = icmp eq i8* %15, null
br i1 %22, label %23, label %8
23: ; preds = %21, %3
%24 = tail call i32 @free(i8* %6)
ret void
}