#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 */
int db_warehouse_get_internal_data(char *, void **, int *);
int db_warehouse_get_stock(char *, int *);
int db_warehouse_update_stock(char *, int);
int sequential_increment_stock(char *product_name, int stock,
                               int *updated_stock) {
  int ret, size;
  void *st_int;
  int stock_aux = 0;
  ret = db_warehouse_get_internal_data(product_name, &st_int, &size);
  if (ret == 0) {
    ret = db_warehouse_get_stock(product_name, &stock_aux);
    stock_aux += stock;
    ret = db_warehouse_update_stock(product_name, stock_aux);
    *updated_stock = stock_aux;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sequential_increment_stock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <db_warehouse_get_internal_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1199 <sequential_increment_stock+0x69>
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <db_warehouse_get_stock@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <db_warehouse_update_stock@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sequential_increment_stock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1030 <db_warehouse_get_internal_data@plt>
test   %eax,%eax
jne    117b <sequential_increment_stock+0x4b>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <db_warehouse_get_stock@plt>
add    (%rsp),%ebp
mov    %ebp,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <db_warehouse_update_stock@plt>
mov    (%rsp),%ecx
mov    %ecx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sequential_increment_stock(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %10
%11 = load i8*, i8** %4
%12 = call i32 @db_warehouse_get_internal_data(i8* %11, i8** %9, i32* %8)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i32 @db_warehouse_get_stock(i8* %16, i32* %10)
store i32 %17, i32* %7
%18 = load i32, i32* %5
%19 = load i32, i32* %10
%20 = add nsw i32 %19, %18
store i32 %20, i32* %10
%21 = load i8*, i8** %4
%22 = load i32, i32* %10
%23 = call i32 @db_warehouse_update_stock(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %10
%25 = load i32*, i32** %6
store i32 %24, i32* %25
br label %26
26: ; preds = %15, %3
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @sequential_increment_stock(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i8** %5 to i8*
%9 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%10 = call i32 @db_warehouse_get_internal_data(i8* %0, i8** %5, i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = call i32 @db_warehouse_get_stock(i8* %0, i32* %6)
%14 = load i32, i32* %6
%15 = add nsw i32 %14, %1
store i32 %15, i32* %6
%16 = call i32 @db_warehouse_update_stock(i8* %0, i32 %15)
%17 = load i32, i32* %6
store i32 %17, i32* %2
br label %18
18: ; preds = %12, %3
%19 = phi i32 [ %16, %12 ], [ %10, %3 ]
ret i32 %19
}