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

/* Variables and functions */
scalar_t__ db_write(struct resource *, int);
int remote_write(int, struct resource *);
int store_write(int resourceCount, struct resource *entryList, int thisOnly) {
  if (db_write(entryList, resourceCount)) {
    return 1;
  }
  if (thisOnly)
    return 0;
  return remote_write(resourceCount, entryList);
}


x86 assembly (clang, -O0):
<store_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <db_write@plt>
cmp    $0x0,%rax
je     1154 <store_write+0x34>
movl   $0x1,-0x4(%rbp)
jmp    1179 <store_write+0x59>
cmpl   $0x0,-0x14(%rbp)
je     116a <store_write+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    1179 <store_write+0x59>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <remote_write@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_write>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
mov    %ebp,%esi
call   1040 <db_write@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    114a <store_write+0x2a>
xor    %eax,%eax
test   %r14d,%r14d
je     114f <store_write+0x2f>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <remote_write@plt>

LLVM IR (-O0):
%struct.resource = type { i32 }
define i32 @store_write(i32 %0, %struct.resource* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.resource*
%7 = alloca i32
store i32 %0, i32* %5
store %struct.resource* %1, %struct.resource** %6
store i32 %2, i32* %7
%8 = load %struct.resource*, %struct.resource** %6
%9 = load i32, i32* %5
%10 = call i64 @db_write(%struct.resource* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 1, i32* %4
br label %21
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %4
br label %21
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load %struct.resource*, %struct.resource** %6
%20 = call i32 @remote_write(i32 %18, %struct.resource* %19)
store i32 %20, i32* %4
br label %21
21: ; preds = %17, %16, %12
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.resource = type { i32 }
define i32 @store_write(i32 %0, %struct.resource* %1, i32 %2) {
%4 = tail call i64 @db_write(%struct.resource* %1, i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @remote_write(i32 %0, %struct.resource* %1)
br label %10
10: ; preds = %6, %3, %8
%11 = phi i32 [ %9, %8 ], [ 1, %3 ], [ 0, %6 ]
ret i32 %11
}