#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 sscanf(char *, char *, char *);
char *strchr(char const *, char);
int /*<<< orphan*/ strmcmp(char const *, char const *);
char *scan_acpi_value(const char *buf, const char *key) {
  char *ptr;
  static char ret[256];
  do {
    ptr = strchr(buf, '\n');
    if (!strmcmp(buf, key)) {
      ptr = strchr(buf, '=');
      if (ptr) {
        if (sscanf(ptr + 1, "%255s", ret) == 1)
          return ret;
        else
          return NULL;
      } else {
        return NULL;
      }
    }
    if (ptr)
      ptr++;
    buf = ptr;
  } while (buf != NULL);
  return NULL;
}


x86 assembly (clang, -O0):
<scan_acpi_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strmcmp@plt>
cmp    $0x0,%eax
jne    11d3 <scan_acpi_value+0xa3>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c6 <scan_acpi_value+0x96>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe6c(%rip),%rsi
lea    0x2eb5(%rip),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b9 <scan_acpi_value+0x89>
lea    0x2ea0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1205 <scan_acpi_value+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    1205 <scan_acpi_value+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    1205 <scan_acpi_value+0xd5>
cmpq   $0x0,-0x20(%rbp)
je     11ea <scan_acpi_value+0xba>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1140 <scan_acpi_value+0x10>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_acpi_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strmcmp@plt>
test   %eax,%eax
je     117a <scan_acpi_value+0x4a>
lea    0x1(%rbx),%r12
test   %rbx,%rbx
jne    1150 <scan_acpi_value+0x20>
jmp    11b8 <scan_acpi_value+0x88>
mov    %r12,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11b5 <scan_acpi_value+0x85>
add    $0x1,%rax
lea    0xe69(%rip),%rsi
lea    0x2eb2(%rip),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
cmove  %rbx,%r14
jmp    11b8 <scan_acpi_value+0x88>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@scan_acpi_value.ret = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"%255s\00"
define i8* @scan_acpi_value(i8* %0, i8* %1) {
br label %3
3: ; preds = %16, %2
%4 = phi i8* [ %0, %2 ], [ %18, %16 ]
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 10)
%6 = tail call i32 @strmcmp(i8* %4, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 61)
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @scan_acpi_value.ret, i64 0, i64 0))
%14 = icmp eq i32 %13, 1
%15 = select i1 %14, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @scan_acpi_value.ret, i64 0, i64 0), i8* null
br label %19
16: ; preds = %3
%17 = icmp eq i8* %5, null
%18 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %17, label %19, label %3
19: ; preds = %16, %8, %11
%20 = phi i8* [ %15, %11 ], [ null, %8 ], [ null, %16 ]
ret i8* %20
}