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

/* Variables and functions */
int /*<<< orphan*/ beginTrans(int /*<<< orphan*/);
int /*<<< orphan*/ commitTrans();
int doAddAlert(struct Alert *, int);
int getNextId(char *);
int /*<<< orphan*/ rollbackTrans();
int addAlert(struct Alert *alert) {
  beginTrans(0);
  int alertId = getNextId("SELECT max(id) FROM alert;");
  int status = doAddAlert(alert, alertId);
  if (status == 1) {
    commitTrans();
    return alertId;
  } else {
    rollbackTrans();
    return -1;
  }
}


x86 assembly (clang, -O0):
<addAlert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %edi,%edi
call   1050 <beginTrans@plt>
lea    0xe96(%rip),%rdi
call   1070 <getNextId@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <doAddAlert@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    119d <addAlert+0x4d>
mov    $0x0,%al
call   1030 <commitTrans@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <addAlert+0x5b>
mov    $0x0,%al
call   1040 <rollbackTrans@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addAlert>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <beginTrans@plt>
lea    0xe9b(%rip),%rdi
call   1070 <getNextId@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <doAddAlert@plt>
cmp    $0x1,%eax
jne    1184 <addAlert+0x34>
xor    %eax,%eax
call   1030 <commitTrans@plt>
jmp    1190 <addAlert+0x40>
xor    %eax,%eax
call   1040 <rollbackTrans@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.Alert = type { i32 }
@.str = [27 x i8] c"SELECT max(id) FROM alert;\00"
define i32 @addAlert(%struct.Alert* %0) {
%2 = alloca i32
%3 = alloca %struct.Alert*
%4 = alloca i32
%5 = alloca i32
store %struct.Alert* %0, %struct.Alert** %3
%6 = call i32 @beginTrans(i32 0)
%7 = call i32 @getNextId(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %4
%8 = load %struct.Alert*, %struct.Alert** %3
%9 = load i32, i32* %4
%10 = call i32 @doAddAlert(%struct.Alert* %8, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 (...) @commitTrans()
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %18
16: ; preds = %1
%17 = call i32 (...) @rollbackTrans()
store i32 -1, i32* %2
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.Alert = type { i32 }
@.str = [27 x i8] c"SELECT max(id) FROM alert;\00"
define i32 @addAlert(%struct.Alert* %0) {
%2 = tail call i32 @beginTrans(i32 0)
%3 = tail call i32 @getNextId(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @doAddAlert(%struct.Alert* %0, i32 %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (...) @commitTrans()
br label %10
8: ; preds = %1
%9 = tail call i32 (...) @rollbackTrans()
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ %3, %6 ], [ -1, %8 ]
ret i32 %11
}