#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 *nvram_get(char const *);
int /*<<< orphan*/ nvram_set(char const *, char *);
int snprintf(char *, int, char *, char const *, ...);
int ezplib_append_rule(const char *rule_set, const char *new_rule) {
  char buf[8192];
  int len;
  char *old_rules;
  if (!rule_set || !*rule_set || !new_rule) {
    return -1;
  }
  old_rules = nvram_get(rule_set);
  if (!old_rules) {
    return -3;
  }
  if (!*old_rules) {
    len = snprintf(buf, 8192, "%s", new_rule);
  } else {
    len = snprintf(buf, 8192, "%s%s%s", old_rules, "|", new_rule);
  }
  if (len >= 8192) {
    return -2;
  }
  nvram_set(rule_set, buf);
  return len;
}


x86 assembly (clang, -O0):
<ezplib_append_rule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <ezplib_append_rule+0x36>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1166 <ezplib_append_rule+0x36>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <ezplib_append_rule+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <ezplib_append_rule+0x10c>
mov    -0x10(%rbp),%rdi
call   1050 <nvram_get@plt>
mov    %rax,-0x2030(%rbp)
cmpq   $0x0,-0x2030(%rbp)
jne    119c <ezplib_append_rule+0x6c>
movl   $0xfffffffd,-0x4(%rbp)
jmp    123c <ezplib_append_rule+0x10c>
mov    -0x2030(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11d5 <ezplib_append_rule+0xa5>
lea    -0x2020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2000,%esi
lea    0xe41(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x2024(%rbp)
jmp    1207 <ezplib_append_rule+0xd7>
lea    -0x2020(%rbp),%rdi
mov    -0x2030(%rbp),%rcx
mov    -0x18(%rbp),%r9
mov    $0x2000,%esi
lea    0xe0d(%rip),%rdx
lea    0xe0d(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x2000,-0x2024(%rbp)
jl     1223 <ezplib_append_rule+0xf3>
movl   $0xfffffffe,-0x4(%rbp)
jmp    123c <ezplib_append_rule+0x10c>
mov    -0x10(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
call   1030 <nvram_set@plt>
mov    -0x2024(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ezplib_append_rule>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11cc <ezplib_append_rule+0x9c>
mov    %rsi,%r14
test   %rsi,%rsi
je     11cc <ezplib_append_rule+0x9c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11cc <ezplib_append_rule+0x9c>
mov    %rbx,%rdi
call   1050 <nvram_get@plt>
test   %rax,%rax
je     1190 <ezplib_append_rule+0x60>
cmpb   $0x0,(%rax)
je     1197 <ezplib_append_rule+0x67>
lea    0xe8e(%rip),%rdx
lea    0xe8e(%rip),%r8
mov    %rsp,%rdi
mov    $0x2000,%esi
mov    %rax,%rcx
mov    %r14,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11b0 <ezplib_append_rule+0x80>
mov    $0xfffffffd,%eax
jmp    11cc <ezplib_append_rule+0x9c>
lea    0xe66(%rip),%rdx
mov    %rsp,%rdi
mov    $0x2000,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebp
mov    $0xfffffffe,%eax
cmp    $0x1fff,%ebp
jg     11cc <ezplib_append_rule+0x9c>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <nvram_set@plt>
mov    %ebp,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"|\00"
define i32 @ezplib_append_rule(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [8192 x i8]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %11, %2
store i32 -1, i32* %3
br label %47
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i8* @nvram_get(i8* %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 -3, i32* %3
br label %47
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%31 = load i8*, i8** %5
%32 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %30, i32 8192, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 %32, i32* %7
br label %38
33: ; preds = %25
%34 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = load i8*, i8** %5
%37 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %34, i32 8192, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %36)
store i32 %37, i32* %7
br label %38
38: ; preds = %33, %29
%39 = load i32, i32* %7
%40 = icmp sge i32 %39, 8192
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 -2, i32* %3
br label %47
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%45 = call i32 @nvram_set(i8* %43, i8* %44)
%46 = load i32, i32* %7
store i32 %46, i32* %3
br label %47
47: ; preds = %42, %41, %24, %18
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"|\00"
define i32 @ezplib_append_rule(i8* %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp ne i8 %7, 0
%9 = icmp ne i8* %1, null
%10 = and i1 %9, %8
br i1 %10, label %11, label %26
11: ; preds = %6
%12 = tail call i8* @nvram_get(i8* %0)
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %11
%15 = load i8, i8* %12
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 8192, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %21
19: ; preds = %14
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 8192, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %20, %19 ], [ %18, %17 ]
%23 = icmp sgt i32 %22, 8191
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @nvram_set(i8* %0, i8* %4)
br label %26
26: ; preds = %21, %11, %2, %6, %24
%27 = phi i32 [ %22, %24 ], [ -1, %6 ], [ -1, %2 ], [ -3, %11 ], [ -2, %21 ]
ret i32 %27
}