#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 items {
  int dummy;
};

/* Variables and functions */
struct items *creatitems(int);
int /*<<< orphan*/ freeitems(struct items *);
scalar_t__ readitems(struct items *, char const *);
scalar_t__ readvalue(struct items *, char const *, int *);
int readvaluef(const char *filename, int max, const char *name, int *value) {
  struct items *its;
  its = creatitems(max);
  if (its == NULL)
    return -1;
  if (readitems(its, filename) < 0 || readvalue(its, name, value) < 0) {
    freeitems(its);
    return -1;
  }
  freeitems(its);
  return 0;
}


x86 assembly (clang, -O0):
<readvaluef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <creatitems@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117a <readvaluef+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <readvaluef+0x91>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <readitems@plt>
cmp    $0x0,%rax
jl     11ac <readvaluef+0x6c>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <readvalue@plt>
cmp    $0x0,%rax
jge    11c1 <readvaluef+0x81>
mov    -0x30(%rbp),%rdi
call   1030 <freeitems@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <readvaluef+0x91>
mov    -0x30(%rbp),%rdi
call   1030 <freeitems@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readvaluef>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
mov    %esi,%edi
call   1040 <creatitems@plt>
test   %rax,%rax
je     1187 <readvaluef+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <readitems@plt>
test   %rax,%rax
js     118f <readvaluef+0x4f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <readvalue@plt>
mov    %rax,%r14
sar    $0x3f,%r14
jmp    1195 <readvaluef+0x55>
mov    $0xffffffff,%r14d
jmp    119d <readvaluef+0x5d>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1030 <freeitems@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.items = type { i32 }
define i32 @readvaluef(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = tail call %struct.items* @creatitems(i32 %1)
%6 = icmp eq %struct.items* %5, null
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i64 @readitems(%struct.items* %5, i8* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i64 @readvalue(%struct.items* %5, i8* %2, i32* %3)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ -1, %7 ], [ %13, %10 ]
%16 = tail call i32 @freeitems(%struct.items* %5)
br label %17
17: ; preds = %14, %4
%18 = phi i32 [ -1, %4 ], [ %15, %14 ]
ret i32 %18
}