#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)) {
      if ((ptr = strchr(buf, '='))) {
        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    11ba <scan_acpi_num+0x8a>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ae <scan_acpi_num+0x7e>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe66(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <scan_acpi_num+0xbb>
movl   $0x0,-0x4(%rbp)
jmp    11eb <scan_acpi_num+0xbb>
cmpq   $0x0,-0x20(%rbp)
je     11d1 <scan_acpi_num+0xa1>
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 = %33, %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 %25, 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 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %37
24: ; preds = %15
store i32 0, i32* %3
br label %37
25: ; preds = %8
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
br label %31
31: ; preds = %28, %25
%32 = load i8*, i8** %6
store i8* %32, i8** %4
br label %33
33: ; preds = %31
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %8, label %36
36: ; preds = %33
store i32 0, i32* %3
br label %37
37: ; preds = %36, %24, %19
%38 = load i32, i32* %3
ret i32 %38
}

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
}