#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 const *, char *, unsigned long *);
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) {
    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   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <scan_one+0x41>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b9 <scan_one+0x89>
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    0xe6e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11b1 <scan_one+0x81>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <scan_one+0x89>
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   1050 <strstr@plt>
movq   $0x0,(%rsp)
test   %rax,%rax
je     1176 <scan_one+0x46>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
lea    0xea0(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    117f <scan_one+0x4f>
mov    (%rsp),%rax
jmp    1181 <scan_one+0x51>
mov    $0xffffffffffffffff,%rax
jmp    1181 <scan_one+0x51>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [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 %14, label %13
13: ; preds = %2
store i64 -1, i64* %3
br label %25
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %7)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %14
store i64 0, i64* %3
br label %25
23: ; preds = %14
%24 = load i64, i64* %7
store i64 %24, i64* %3
br label %25
25: ; preds = %23, %22, %13
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
@.str = [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 %15, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%12 = icmp eq i32 %11, 1
%13 = load i64, i64* %3
%14 = select i1 %12, i64 %13, i64 0
br label %15
15: ; preds = %7, %2
%16 = phi i64 [ -1, %2 ], [ %14, %7 ]
ret i64 %16
}