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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ nvpair_insert_string(struct nvpair *, char *, char *);
char *strtok(char *, char *);
char *xxstrdup(char const *);
void nvpair_parse(struct nvpair *n, const char *data) {
  char *text = xxstrdup(data);
  char *name, *value;
  name = strtok(text, " ");
  while (name) {
    value = strtok(0, "\n");
    if (value) {
      nvpair_insert_string(n, name, value);
    } else {
      break;
    }
    name = strtok(0, " ");
  }
  free(text);
}


x86 assembly (clang, -O0):
<nvpair_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <xxstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cf <nvpair_parse+0x8f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe7b(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b1 <nvpair_parse+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <nvpair_insert_string@plt>
jmp    11b6 <nvpair_parse+0x76>
jmp    11cf <nvpair_parse+0x8f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1171 <nvpair_parse+0x31>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvpair_parse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1060 <xxstrdup@plt>
mov    %rax,%r14
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11af <nvpair_parse+0x6f>
mov    %rax,%rbx
lea    0xe8d(%rip),%r15
lea    0xe84(%rip),%r12
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11af <nvpair_parse+0x6f>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <nvpair_insert_string@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <nvpair_parse+0x40>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.nvpair = type { i32 }
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @nvpair_parse(%struct.nvpair* %0, i8* %1) {
%3 = alloca %struct.nvpair*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store %struct.nvpair* %0, %struct.nvpair** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @xxstrdup(i8* %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
br label %12
12: ; preds = %25, %2
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load %struct.nvpair*, %struct.nvpair** %3
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 @nvpair_insert_string(%struct.nvpair* %20, i8* %21, i8* %22)
br label %25
24: ; preds = %15
br label %27
25: ; preds = %19
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %6
br label %12
27: ; preds = %24, %12
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
%struct.nvpair = type { i32 }
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @nvpair_parse(%struct.nvpair* %0, i8* %1) {
%3 = tail call i8* @xxstrdup(i8* %1)
%4 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %2, %10
%7 = phi i8* [ %12, %10 ], [ %4, %2 ]
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i32 @nvpair_insert_string(%struct.nvpair* %0, i8* %7, i8* %8)
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %6
14: ; preds = %10, %6, %2
%15 = tail call i32 @free(i8* %3)
ret void
}