#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int sscanf(char const *, char *, unsigned long *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
char *strstr(char const *, char const *);
unsigned long int scan_one(const char *buff, const char *key) {
  const char *b = strstr(buff, key);
  unsigned long val = 0;
  if (!b) {
    fprintf(stderr, "ERROR: no hit for %s\n", key);
    return ~0UL;
  }
  if (sscanf(b + strlen(key), " %lu", &val) != 1)
    return 0;
  return val;
}


x86 assembly (clang, -O0):
<scan_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <scan_one+0x5a>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e2 <scan_one+0xa2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe5b(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11da <scan_one+0x9a>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <scan_one+0xa2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_one>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <strstr@plt>
movq   $0x0,(%rsp)
test   %rax,%rax
je     1186 <scan_one+0x46>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
lea    0xea6(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11a7 <scan_one+0x67>
mov    (%rsp),%rax
jmp    11a9 <scan_one+0x69>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffffffffffff,%rax
jmp    11a9 <scan_one+0x69>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"ERROR: no hit for %s\0A\00"
@.str.1 = [5 x i8] c" %lu\00"
define i64 @scan_one(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i8* @strstr(i8* %8, i8* %9)
store i8* %10, i8** %6
store i64 0, i64* %7
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
store i64 -1, i64* %3
br label %28
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %7)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %17
store i64 0, i64* %3
br label %28
26: ; preds = %17
%27 = load i64, i64* %7
store i64 %27, i64* %3
br label %28
28: ; preds = %26, %25, %13
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"ERROR: no hit for %s\0A\00"
@.str.1 = [5 x i8] c" %lu\00"
define i64 @scan_one(i8* %0, i8* %1) {
%3 = alloca i64
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %18
10: ; preds = %2
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %4, i64 %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%15 = icmp eq i32 %14, 1
%16 = load i64, i64* %3
%17 = select i1 %15, i64 %16, i64 0
br label %18
18: ; preds = %10, %7
%19 = phi i64 [ -1, %7 ], [ %17, %10 ]
ret i64 %19
}