#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*/ report_error(char *, char *, char **);
char *strtok(char *, char *);
char *trim(char *);
bool parse_line(char *line, char **key, char **value) {
  char *delimiters = ":\r\n";
  bool found_key_and_value = false;
  *key = NULL;
  *value = NULL;
  if ((*key = strtok(line, delimiters)) != NULL) {
    if ((*value = strtok(NULL, delimiters)) != NULL) {
      found_key_and_value = true;
    } else {
      report_error("%s: missing value for key: %s\n", "/proc/pmu/info", key);
    }
  }
  *key = trim(*key);
  *value = trim(*value);
  return found_key_and_value;
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strtok@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     11d0 <parse_line+0xa0>
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     11b4 <parse_line+0x84>
movl   $0x1,-0x24(%rbp)
jmp    11cb <parse_line+0x9b>
mov    -0x10(%rbp),%rdx
lea    0xe45(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <report_error@plt>
jmp    11d0 <parse_line+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <trim@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <trim@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
lea    0xeb1(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     118d <parse_line+0x5d>
lea    0xe9d(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
mov    %rax,(%r14)
mov    $0x1,%ebp
test   %rax,%rax
jne    118f <parse_line+0x5f>
lea    0xe86(%rip),%rdi
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdx
call   1040 <report_error@plt>
xor    %ebp,%ebp
mov    (%rbx),%rdi
call   1030 <trim@plt>
mov    %rax,(%rbx)
mov    (%r14),%rdi
call   1030 <trim@plt>
mov    %rax,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c":\0D\0A\00"
@.str.1 = [31 x i8] c"%s: missing value for key: %s\0A\00"
@.str.2 = [15 x i8] c"/proc/pmu/info\00"
define i32 @parse_line(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 0, i32* %8
%9 = load i8**, i8*** %5
store i8* null, i8** %9
%10 = load i8**, i8*** %6
store i8* null, i8** %10
%11 = load i8*, i8** %4
%12 = load i8*, i8** %7
%13 = call i8* @strtok(i8* %11, i8* %12)
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
%15 = icmp ne i8* %13, null
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = call i8* @strtok(i8* null, i8* %17)
%19 = load i8**, i8*** %6
store i8* %18, i8** %19
%20 = icmp ne i8* %18, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %8
br label %25
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = call i32 @report_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %23)
br label %25
25: ; preds = %22, %21
br label %26
26: ; preds = %25, %3
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = call i8* @trim(i8* %28)
%30 = load i8**, i8*** %5
store i8* %29, i8** %30
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = call i8* @trim(i8* %32)
%34 = load i8**, i8*** %6
store i8* %33, i8** %34
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
@.str = [4 x i8] c":\0D\0A\00"
@.str.1 = [31 x i8] c"%s: missing value for key: %s\0A\00"
@.str.2 = [15 x i8] c"/proc/pmu/info\00"
define i32 @parse_line(i8* %0, i8** %1, i8** nocapture %2) {
store i8* null, i8** %1
store i8* null, i8** %2
%4 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @report_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %1)
br label %11
11: ; preds = %6, %9, %3
%12 = phi i32 [ 0, %9 ], [ 0, %3 ], [ 1, %6 ]
%13 = load i8*, i8** %1
%14 = tail call i8* @trim(i8* %13)
store i8* %14, i8** %1
%15 = load i8*, i8** %2
%16 = tail call i8* @trim(i8* %15)
store i8* %16, i8** %2
ret i32 %12
}