#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 */
int /*<<< orphan*/ additem(struct items *, char const *, int);
struct items *creatitems(int);
int /*<<< orphan*/ freeitems(struct items *);
int /*<<< orphan*/ readitems(struct items *, char const *);
scalar_t__ saveitems(struct items *, char const *);
int additemf(const char *filename, int max, const char *name, int value) {
  struct items *its;
  its = creatitems(max);
  if (its == NULL)
    return -1;
  readitems(its, filename);
  additem(its, name, value);
  if (saveitems(its, filename) >= 0) {
    freeitems(its);
    return 0;
  }
  freeitems(its);
  return -1;
}


x86 assembly (clang, -O0):
<additemf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <creatitems@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1189 <additemf+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <additemf+0x92>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <readitems@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <additem@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <saveitems@plt>
cmp    $0x0,%rax
jl     11d2 <additemf+0x82>
mov    -0x30(%rbp),%rdi
call   1040 <freeitems@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <additemf+0x92>
mov    -0x30(%rbp),%rdi
call   1040 <freeitems@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<additemf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %rdi,%r14
mov    %esi,%edi
call   1050 <creatitems@plt>
test   %rax,%rax
je     11a4 <additemf+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <readitems@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1030 <additem@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <saveitems@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <freeitems@plt>
sar    $0x3f,%rbp
jmp    11a9 <additemf+0x59>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.items = type { i32 }
define i32 @additemf(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 %34
16: ; preds = %4
%17 = load %struct.items*, %struct.items** %10
%18 = load i8*, i8** %6
%19 = call i32 @readitems(%struct.items* %17, i8* %18)
%20 = load %struct.items*, %struct.items** %10
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = call i32 @additem(%struct.items* %20, i8* %21, i32 %22)
%24 = load %struct.items*, %struct.items** %10
%25 = load i8*, i8** %6
%26 = call i64 @saveitems(%struct.items* %24, i8* %25)
%27 = icmp sge i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = load %struct.items*, %struct.items** %10
%30 = call i32 @freeitems(%struct.items* %29)
store i32 0, i32* %5
br label %34
31: ; preds = %16
%32 = load %struct.items*, %struct.items** %10
%33 = call i32 @freeitems(%struct.items* %32)
store i32 -1, i32* %5
br label %34
34: ; preds = %31, %28, %15
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.items = type { i32 }
define i32 @additemf(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 %14, label %7
7: ; preds = %4
%8 = tail call i32 @readitems(%struct.items* %5, i8* %0)
%9 = tail call i32 @additem(%struct.items* %5, i8* %2, i32 %3)
%10 = tail call i64 @saveitems(%struct.items* %5, i8* %0)
%11 = tail call i32 @freeitems(%struct.items* %5)
%12 = ashr i64 %10, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %7, %4
%15 = phi i32 [ -1, %4 ], [ %13, %7 ]
ret i32 %15
}