#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 */
scalar_t__ dao_keyvalue_edit_int(char *, int);
scalar_t__ dao_keyvalue_edit_text(char *, char *);
int /*<<< orphan*/ free(char *);
char *helper_serialize_str_array(char **, size_t);
bool firmware_dao_update_latest_firmware(int version, char *release, char *url,
                                         char **changes, size_t nrchanges,
                                         char *firmware_path, bool newer,
                                         char *signature) {
  if (dao_keyvalue_edit_int("firmware_version", version) != 0)
    return false;
  if (dao_keyvalue_edit_text("firmware_release", release) != 0)
    return false;
  if (dao_keyvalue_edit_text("firmware_url", url) != 0)
    return false;
  if (dao_keyvalue_edit_text("firmware_path", firmware_path) != 0)
    return false;
  if (dao_keyvalue_edit_int("firmware_newer", newer ? 1 : 0) != 0)
    return false;
  if (dao_keyvalue_edit_text("firmware_sig", signature) != 0)
    return false;
  char *ser_changes = helper_serialize_str_array(changes, nrchanges);
  if (dao_keyvalue_edit_text("firmware_changes", ser_changes) != 0) {
    free(ser_changes);
    return false;
  }
  free(ser_changes);
  return true;
}


x86 assembly (clang, -O0):
<firmware_dao_update_latest_firmware>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe90(%rip),%rdi
call   1050 <dao_keyvalue_edit_int@plt>
cmp    $0x0,%rax
je     118b <firmware_dao_update_latest_firmware+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
cmp    $0x0,%rax
je     11b1 <firmware_dao_update_latest_firmware+0x71>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    -0x18(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
cmp    $0x0,%rax
je     11d7 <firmware_dao_update_latest_firmware+0x97>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    -0x30(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
cmp    $0x0,%rax
je     11fd <firmware_dao_update_latest_firmware+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    0x10(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe29(%rip),%rdi
call   1050 <dao_keyvalue_edit_int@plt>
cmp    $0x0,%rax
je     122f <firmware_dao_update_latest_firmware+0xef>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    0x18(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
cmp    $0x0,%rax
je     1255 <firmware_dao_update_latest_firmware+0x115>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <helper_serialize_str_array@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
cmp    $0x0,%rax
je     1295 <firmware_dao_update_latest_firmware+0x155>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <firmware_dao_update_latest_firmware+0x165>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firmware_dao_update_latest_firmware>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r12
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%esi
lea    0xe9d(%rip),%rdi
call   1050 <dao_keyvalue_edit_int@plt>
xor    %r13d,%r13d
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
lea    0xe96(%rip),%rdi
mov    %rbp,%rsi
call   1040 <dao_keyvalue_edit_text@plt>
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <dao_keyvalue_edit_text@plt>
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
lea    0xe88(%rip),%rdi
mov    %r12,%rsi
call   1040 <dao_keyvalue_edit_text@plt>
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
xor    %esi,%esi
cmpl   $0x0,0x40(%rsp)
setne  %sil
lea    0xe77(%rip),%rdi
call   1050 <dao_keyvalue_edit_int@plt>
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
mov    0x48(%rsp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <dao_keyvalue_edit_text@plt>
test   %rax,%rax
jne    1215 <firmware_dao_update_latest_firmware+0xd5>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <helper_serialize_str_array@plt>
mov    %rax,%rbx
lea    0xe5e(%rip),%rdi
mov    %rax,%rsi
call   1040 <dao_keyvalue_edit_text@plt>
xor    %r13d,%r13d
test   %rax,%rax
sete   %r13b
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"firmware_version\00"
@.str.1 = [17 x i8] c"firmware_release\00"
@.str.2 = [13 x i8] c"firmware_url\00"
@.str.3 = [14 x i8] c"firmware_path\00"
@.str.4 = [15 x i8] c"firmware_newer\00"
@.str.5 = [13 x i8] c"firmware_sig\00"
@.str.6 = [17 x i8] c"firmware_changes\00"
define i32 @firmware_dao_update_latest_firmware(i32 %0, i8* %1, i8* %2, i8** %3, i64 %4, i8* %5, i32 %6, i8* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8**
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
store i32 %0, i32* %10
store i8* %1, i8** %11
store i8* %2, i8** %12
store i8** %3, i8*** %13
store i64 %4, i64* %14
store i8* %5, i8** %15
store i32 %6, i32* %16
store i8* %7, i8** %17
%19 = load i32, i32* %10
%20 = call i64 @dao_keyvalue_edit_int(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %8
store i32 0, i32* %9
br label %64
23: ; preds = %8
%24 = load i8*, i8** %11
%25 = call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 0, i32* %9
br label %64
28: ; preds = %23
%29 = load i8*, i8** %12
%30 = call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 0, i32* %9
br label %64
33: ; preds = %28
%34 = load i8*, i8** %15
%35 = call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 0, i32* %9
br label %64
38: ; preds = %33
%39 = load i32, i32* %16
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 1, i32 0
%43 = call i64 @dao_keyvalue_edit_int(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 0, i32* %9
br label %64
46: ; preds = %38
%47 = load i8*, i8** %17
%48 = call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 0, i32* %9
br label %64
51: ; preds = %46
%52 = load i8**, i8*** %13
%53 = load i64, i64* %14
%54 = call i8* @helper_serialize_str_array(i8** %52, i64 %53)
store i8* %54, i8** %18
%55 = load i8*, i8** %18
%56 = call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = load i8*, i8** %18
%60 = call i32 @free(i8* %59)
store i32 0, i32* %9
br label %64
61: ; preds = %51
%62 = load i8*, i8** %18
%63 = call i32 @free(i8* %62)
store i32 1, i32* %9
br label %64
64: ; preds = %61, %58, %50, %45, %37, %32, %27, %22
%65 = load i32, i32* %9
ret i32 %65
}

LLVM IR (-O2):
@.str = [17 x i8] c"firmware_version\00"
@.str.1 = [17 x i8] c"firmware_release\00"
@.str.2 = [13 x i8] c"firmware_url\00"
@.str.3 = [14 x i8] c"firmware_path\00"
@.str.4 = [15 x i8] c"firmware_newer\00"
@.str.5 = [13 x i8] c"firmware_sig\00"
@.str.6 = [17 x i8] c"firmware_changes\00"
define i32 @firmware_dao_update_latest_firmware(i32 %0, i8* %1, i8* %2, i8** %3, i64 %4, i8* %5, i32 %6, i8* %7) {
%9 = tail call i64 @dao_keyvalue_edit_int(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = tail call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = tail call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = tail call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = icmp ne i32 %6, 0
%22 = zext i1 %21 to i32
%23 = tail call i64 @dao_keyvalue_edit_int(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = tail call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = tail call i8* @helper_serialize_str_array(i8** %3, i64 %4)
%30 = tail call i64 @dao_keyvalue_edit_text(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
%32 = tail call i32 @free(i8* %29)
%33 = zext i1 %31 to i32
br label %34
34: ; preds = %28, %25, %20, %17, %14, %11, %8
%35 = phi i32 [ 0, %8 ], [ 0, %11 ], [ 0, %14 ], [ 0, %17 ], [ 0, %20 ], [ 0, %25 ], [ %33, %28 ]
ret i32 %35
}