#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)) {
      if ((ptr = strchr(buf, '='))) {
        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    11d2 <scan_acpi_value+0xa2>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c5 <scan_acpi_value+0x95>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe6d(%rip),%rsi
lea    0x2eb6(%rip),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b8 <scan_acpi_value+0x88>
lea    0x2ea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <scan_acpi_value+0xd4>
movq   $0x0,-0x8(%rbp)
jmp    1204 <scan_acpi_value+0xd4>
movq   $0x0,-0x8(%rbp)
jmp    1204 <scan_acpi_value+0xd4>
cmpq   $0x0,-0x20(%rbp)
je     11e9 <scan_acpi_value+0xb9>
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 = %34, %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 %26, 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 = icmp ne i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @sscanf(i8* %20, 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))
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %18
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @scan_acpi_value.ret, i64 0, i64 0), i8** %3
br label %38
24: ; preds = %18
store i8* null, i8** %3
br label %38
25: ; preds = %14
store i8* null, i8** %3
br label %38
26: ; preds = %7
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %6
store i8* %33, i8** %4
br label %34
34: ; preds = %32
%35 = load i8*, i8** %4
%36 = icmp ne i8* %35, null
br i1 %36, label %7, label %37
37: ; preds = %34
store i8* null, i8** %3
br label %38
38: ; preds = %37, %25, %24, %23
%39 = load i8*, i8** %3
ret i8* %39
}

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
}