#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 */
struct attrset {
  int dummy;
};

/* Variables and functions */
char *attr_find(struct attrset *, char const *);
unsigned long strtoul(char const *, char **, int);
int attr_find_int(struct attrset *set, const char *key) {
  const char *val = attr_find(set, key);
  unsigned long rv;
  char *end;
  if (!val)
    return -1;
  rv = strtoul(val, &end, 10);
  if (!end || end == val || *end)
    return -1;
  return rv;
}


x86 assembly (clang, -O0):
<attr_find_int>:
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   1030 <attr_find@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1158 <attr_find_int+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <attr_find_int+0x8a>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1197 <attr_find_int+0x77>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1197 <attr_find_int+0x77>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a3 <attr_find_int+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <attr_find_int+0x8a>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attr_find_int>:
push   %rbp
push   %rbx
push   %rax
call   1030 <attr_find@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     115b <attr_find_int+0x3b>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     115b <attr_find_int+0x3b>
cmp    %rbx,%rcx
je     115b <attr_find_int+0x3b>
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ebp,%ebp
or     %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.attrset = type { i32 }
define i32 @attr_find_int(%struct.attrset* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.attrset*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store %struct.attrset* %0, %struct.attrset** %4
store i8* %1, i8** %5
%9 = load %struct.attrset*, %struct.attrset** %4
%10 = load i8*, i8** %5
%11 = call i8* @attr_find(%struct.attrset* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %33
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i64 @strtoul(i8* %16, i8** %8, i32 10)
store i64 %17, i64* %7
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i8*, i8** %8
%22 = load i8*, i8** %6
%23 = icmp eq i8* %21, %22
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24, %20, %15
store i32 -1, i32* %3
br label %33
30: ; preds = %24
%31 = load i64, i64* %7
%32 = trunc i64 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %29, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.attrset = type { i32 }
define i32 @attr_find_int(%struct.attrset* %0, i8* %1) {
%3 = alloca i8*
%4 = tail call i8* @attr_find(%struct.attrset* %0, i8* %1)
%5 = bitcast i8** %3 to i8*
%6 = icmp eq i8* %4, null
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = call i64 @strtoul(i8* %4, i8** %3, i32 10)
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
%11 = icmp eq i8* %9, %4
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = load i8, i8* %9
%15 = icmp eq i8 %14, 0
%16 = trunc i64 %8 to i32
%17 = select i1 %15, i32 %16, i32 -1
br label %18
18: ; preds = %13, %7, %2
%19 = phi i32 [ -1, %2 ], [ -1, %7 ], [ %17, %13 ]
ret i32 %19
}