#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 */
char *add_addon(char *, char *, char *);
int /*<<< orphan*/ del_addon(char *, char *);
int /*<<< orphan*/ free(char *);
char *read_configfile(char *);
scalar_t__ strlen(char *);
int write_hmconfig(char *, char *);
int set_addon(char *id, char *addon) {
  int ret = 0;
  char *buffer = read_configfile(addon);
  if (buffer) {
    char *hmconfig = read_configfile("/usr/local/etc/config/hm_addons.cfg");
    if (hmconfig) {
      del_addon(hmconfig, id);
      if (strlen(buffer))
        hmconfig = add_addon(hmconfig, id, buffer);
      ret = write_hmconfig("/usr/local/etc/config/hm_addons.cfg", hmconfig);
      free(hmconfig);
    } else
      ret = 1;
    free(buffer);
  } else
    ret = 1;
  return ret;
}


x86 assembly (clang, -O0):
<set_addon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <read_configfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1215 <set_addon+0xb5>
lea    0xe6a(%rip),%rdi
call   1080 <read_configfile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1200 <set_addon+0xa0>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <del_addon@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     11df <set_addon+0x7f>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <add_addon@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1070 <write_hmconfig@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1207 <set_addon+0xa7>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    121c <set_addon+0xbc>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_addon>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %rsi,%rdi
call   1070 <read_configfile@plt>
test   %rax,%rax
je     11bb <set_addon+0x6b>
mov    %rax,%r14
lea    0xe8f(%rip),%rdi
call   1070 <read_configfile@plt>
test   %rax,%rax
je     11c2 <set_addon+0x72>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <del_addon@plt>
cmpb   $0x0,(%r14)
je     11a0 <set_addon+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <add_addon@plt>
mov    %rax,%rbx
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
call   1060 <write_hmconfig@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11c7 <set_addon+0x77>
mov    $0x1,%ebp
jmp    11cf <set_addon+0x7f>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"/usr/local/etc/config/hm_addons.cfg\00"
define i32 @set_addon(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
%9 = call i8* @read_configfile(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %37
12: ; preds = %2
%13 = call i8* @read_configfile(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = load i8*, i8** %3
%19 = call i32 @del_addon(i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = call i64 @strlen(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8*, i8** %7
%25 = load i8*, i8** %3
%26 = load i8*, i8** %6
%27 = call i8* @add_addon(i8* %24, i8* %25, i8* %26)
store i8* %27, i8** %7
br label %28
28: ; preds = %23, %16
%29 = load i8*, i8** %7
%30 = call i32 @write_hmconfig(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 %30, i32* %5
%31 = load i8*, i8** %7
%32 = call i32 @free(i8* %31)
br label %34
33: ; preds = %12
store i32 1, i32* %5
br label %34
34: ; preds = %33, %28
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
br label %38
37: ; preds = %2
store i32 1, i32* %5
br label %38
38: ; preds = %37, %34
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [36 x i8] c"/usr/local/etc/config/hm_addons.cfg\00"
define i32 @set_addon(i8* %0, i8* %1) {
%3 = tail call i8* @read_configfile(i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = tail call i8* @read_configfile(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %5
%9 = tail call i32 @del_addon(i8* %6, i8* %0)
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i8* @add_addon(i8* %6, i8* %0, i8* %3)
br label %14
14: ; preds = %12, %8
%15 = phi i8* [ %13, %12 ], [ %6, %8 ]
%16 = tail call i32 @write_hmconfig(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @free(i8* %15)
br label %18
18: ; preds = %5, %14
%19 = phi i32 [ %16, %14 ], [ 1, %5 ]
%20 = tail call i32 @free(i8* %3)
br label %21
21: ; preds = %2, %18
%22 = phi i32 [ %19, %18 ], [ 1, %2 ]
ret i32 %22
}