#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*/ ffpmsg(char *);
scalar_t__ sprintf(char *, char *, long);
int ffi2c(long ival, char *cval, int *status) {
  if (*status > 0)
    return (*status);
  cval[0] = '\0';
  if (sprintf(cval, "%ld", ival) < 0) {
    ffpmsg("Error in ffi2c converting integer to string");
    *status = 401;
  }
  return (*status);
}


x86 assembly (clang, -O0):
<ffi2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    114f <ffi2c+0x2f>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <ffi2c+0x73>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe9b(%rip),%rsi
call   1040 <sprintf@plt>
cmp    $0x0,%rax
jge    118a <ffi2c+0x6a>
lea    0xe89(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x191,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffi2c>:
push   %rbx
mov    %rdx,%rbx
mov    (%rdx),%eax
test   %eax,%eax
jle    112c <ffi2c+0xc>
pop    %rbx
ret
mov    %rdi,%rdx
movb   $0x0,(%rsi)
lea    0xec7(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1040 <sprintf@plt>
test   %rax,%rax
js     114d <ffi2c+0x2d>
mov    (%rbx),%eax
pop    %rbx
ret
lea    0xeb0(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x191,(%rbx)
mov    $0x191,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [44 x i8] c"Error in ffi2c converting integer to string\00"
define i32 @ffi2c(i64 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
%9 = load i32, i32* %8
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
store i32 %13, i32* %4
br label %27
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 0, i8* %16
%17 = load i8*, i8** %6
%18 = load i64, i64* %5
%19 = call i64 @sprintf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @ffpmsg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %7
store i32 401, i32* %23
br label %24
24: ; preds = %21, %14
%25 = load i32*, i32** %7
%26 = load i32, i32* %25
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %11
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [44 x i8] c"Error in ffi2c converting integer to string\00"
define i32 @ffi2c(i64 %0, i8* %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
store i8 0, i8* %1
%7 = tail call i64 @sprintf(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = load i32, i32* %2
br label %13
11: ; preds = %6
%12 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 401, i32* %2
br label %13
13: ; preds = %11, %9, %3
%14 = phi i32 [ %4, %3 ], [ %10, %9 ], [ 401, %11 ]
ret i32 %14
}