#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 /*<<< orphan*/ sprintf(char *, char *, int);
char *form_get_next_reference_number(int *form_current_reference_number) {
  int current_reference_number;
  static char return_reference_number[128];
  current_reference_number = *form_current_reference_number;
  if (!current_reference_number)
    current_reference_number = 1;
  *form_current_reference_number = current_reference_number + 1;
  sprintf(return_reference_number, "%d", current_reference_number);
  return return_reference_number;
}


x86 assembly (clang, -O0):
<form_get_next_reference_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1136 <form_get_next_reference_number+0x26>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edx
lea    0x2ef4(%rip),%rdi
lea    0xead(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ee1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<form_get_next_reference_number>:
push   %rbx
mov    (%rdi),%eax
test   %eax,%eax
mov    $0x1,%edx
cmovne %eax,%edx
lea    0x1(%rdx),%eax
mov    %eax,(%rdi)
lea    0x2f17(%rip),%rbx
lea    0xed0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@form_get_next_reference_number.return_reference_number = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @form_get_next_reference_number(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* %4
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 1, i32* %3
br label %9
9: ; preds = %8, %1
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = load i32*, i32** %2
store i32 %11, i32* %12
%13 = load i32, i32* %3
%14 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @form_get_next_reference_number.return_reference_number, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @form_get_next_reference_number.return_reference_number, i64 0, i64 0)
}

LLVM IR (-O2):
@form_get_next_reference_number.return_reference_number = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @form_get_next_reference_number(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i32 1, i32 %2
%5 = add nsw i32 %4, 1
store i32 %5, i32* %0
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @form_get_next_reference_number.return_reference_number, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @form_get_next_reference_number.return_reference_number, i64 0, i64 0)
}