#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 */
char *strchr(char *, char);
scalar_t__ strcmp(char *, char const *);
char *strdup(char *);
char *strtok_r(char *, char *, char **);
char *uevent_find_line(char *haystack, const char *needle) {
  char *saveptr = NULL;
  char *line;
  char *key;
  char *value;
  line = strtok_r(haystack, "\n", &saveptr);
  while (line != NULL) {
    key = line;
    value = strchr(line, '=');
    if (!value) {
      goto next_line;
    }
    *value = '\0';
    value++;
    if (strcmp(key, needle) == 0) {
      return strdup(value);
    }
  next_line:
    line = strtok_r(NULL, "\n", &saveptr);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<uevent_find_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1203 <uevent_find_line+0xc3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a5 <uevent_find_line+0x65>
jmp    11e6 <uevent_find_line+0xa6>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <uevent_find_line+0xa1>
mov    -0x38(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    120b <uevent_find_line+0xcb>
jmp    11e6 <uevent_find_line+0xa6>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe0f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
jmp    1170 <uevent_find_line+0x30>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uevent_find_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
movq   $0x0,(%rsp)
lea    0xea3(%rip),%rsi
mov    %rsp,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11ce <uevent_find_line+0x8e>
mov    %rax,%rbx
lea    0xe8c(%rip),%r15
xor    %r14d,%r14d
mov    %rsp,%r12
jmp    1195 <uevent_find_line+0x55>
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d1 <uevent_find_line+0x91>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1180 <uevent_find_line+0x40>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1180 <uevent_find_line+0x40>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
jmp    11d1 <uevent_find_line+0x91>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i8* @uevent_find_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @strtok_r(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %11, i8** %7
br label %12
12: ; preds = %34, %2
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i8*, i8** %7
store i8* %16, i8** %8
%17 = load i8*, i8** %7
%18 = call i8* @strchr(i8* %17, i8 signext 61)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %15
br label %34
22: ; preds = %15
%23 = load i8*, i8** %9
store i8 0, i8* %23
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %9
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i8*, i8** %9
%32 = call i8* @strdup(i8* %31)
store i8* %32, i8** %3
br label %37
33: ; preds = %22
br label %34
34: ; preds = %33, %21
%35 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %35, i8** %7
br label %12
36: ; preds = %12
store i8* null, i8** %3
br label %37
37: ; preds = %36, %30
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define noalias i8* @uevent_find_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2, %17
%8 = phi i8* [ %18, %17 ], [ %5, %2 ]
%9 = call i8* @strchr(i8* %8, i8 signext 61)
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %7
store i8 0, i8* %9
%12 = call i64 @strcmp(i8* %8, i8* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = call i8* @strdup(i8* %15)
br label %20
17: ; preds = %11, %7
%18 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %7
20: ; preds = %17, %2, %14
%21 = phi i8* [ %16, %14 ], [ null, %2 ], [ null, %17 ]
ret i8* %21
}