#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*/ sscanf(char *, char *, int *);
char *strchr(char const *, char);
int /*<<< orphan*/ strmcmp(char const *, char const *);
int scan_acpi_num(const char *buf, const char *key) {
  char *ptr;
  int ret = 0;
  do {
    ptr = strchr(buf, '\n');
    if (!strmcmp(buf, key)) {
      ptr = strchr(buf, '=');
      if (ptr) {
        sscanf(ptr + 1, "%d", &ret);
        return ret;
      } else {
        return 0;
      }
    }
    if (ptr)
      ptr++;
    buf = ptr;
  } while (buf != NULL);
  return 0;
}


x86 assembly (clang, -O0):
<scan_acpi_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%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    11bb <scan_acpi_num+0x8b>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11af <scan_acpi_num+0x7f>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe65(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <scan_acpi_num+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    11ec <scan_acpi_num+0xbc>
cmpq   $0x0,-0x20(%rbp)
je     11d2 <scan_acpi_num+0xa2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <scan_acpi_num+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_acpi_num>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,0xc(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strmcmp@plt>
test   %eax,%eax
je     117a <scan_acpi_num+0x4a>
lea    0x1(%rbx),%r15
test   %rbx,%rbx
jne    1150 <scan_acpi_num+0x20>
jmp    11aa <scan_acpi_num+0x7a>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11aa <scan_acpi_num+0x7a>
add    $0x1,%rax
lea    0xe69(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <sscanf@plt>
mov    0xc(%rsp),%eax
jmp    11ac <scan_acpi_num+0x7c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @scan_acpi_num(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
br label %8
8: ; preds = %34, %2
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 10)
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @strmcmp(i8* %11, i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %8
%16 = load i8*, i8** %4
%17 = call i8* @strchr(i8* %16, i8 signext 61)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%24 = load i32, i32* %7
store i32 %24, i32* %3
br label %38
25: ; preds = %15
store i32 0, i32* %3
br label %38
26: ; preds = %8
%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 %8, label %37
37: ; preds = %34
store i32 0, i32* %3
br label %38
38: ; preds = %37, %25, %20
%39 = load i32, i32* %3
ret i32 %39
}

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