#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
long atol(char *);
scalar_t__ cg_read(char const *, char const *, char *, int);
int strlen(char const *);
char *strstr(char *, char const *);
long cg_read_key_long(const char *cgroup, const char *control,
                      const char *key) {
  char buf[4096];
  char *ptr;
  if (cg_read(cgroup, control, buf, sizeof(buf)))
    return -1;
  ptr = strstr(buf, key);
  if (!ptr)
    return -1;
  return atol(ptr + strlen(key));
}


x86 assembly (clang, -O0):
<cg_read_key_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1020(%rbp),%rdx
mov    $0x1000,%ecx
call   1030 <cg_read@plt>
cmp    $0x0,%rax
je     1187 <cg_read_key_long+0x47>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e5 <cg_read_key_long+0xa5>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    11b9 <cg_read_key_long+0x79>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e5 <cg_read_key_long+0xa5>
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1030(%rbp),%rdi
cltq
add    %rax,%rdi
call   1050 <atol@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_read_key_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdx,%r14
mov    %rsp,%rdx
mov    $0x1000,%ecx
call   1030 <cg_read@plt>
mov    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1193 <cg_read_key_long+0x53>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1193 <cg_read_key_long+0x53>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r15
mov    %r15,%rdi
call   1050 <atol@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @cg_read_key_long(i8* %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [4096 x i8]
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%13 = call i64 @cg_read(i8* %10, i8* %11, i8* %12, i32 4096)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i64 -1, i64* %4
br label %30
16: ; preds = %3
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i8* @strstr(i8* %17, i8* %18)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %16
store i64 -1, i64* %4
br label %30
23: ; preds = %16
%24 = load i8*, i8** %9
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = call i64 @atol(i8* %28)
store i64 %29, i64* %4
br label %30
30: ; preds = %23, %22, %15
%31 = load i64, i64* %4
ret i64 %31
}

LLVM IR (-O2):
define i64 @cg_read_key_long(i8* %0, i8* %1, i8* %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = call i64 @cg_read(i8* %0, i8* %1, i8* %5, i32 4096)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %2)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i32 @strlen(i8* %2)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = call i64 @atol(i8* %14)
br label %16
16: ; preds = %8, %3, %11
%17 = phi i64 [ %15, %11 ], [ -1, %3 ], [ -1, %8 ]
ret i64 %17
}