#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 */
typedef int uint32_t;

/* Variables and functions */
int ntohl(int);
int unpack_int32(uint32_t *int32, uint32_t *outbuf, uint32_t *outsize) {
  if ((NULL == int32) || (NULL == outbuf) || (NULL == outsize)) {
    return -1;
  }
  if (4 > *outsize) {
    return -1;
  }
  *outsize = 4;
  *outbuf = ntohl(*int32);
  return 0;
}


x86 assembly (clang, -O0):
<unpack_int32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1148 <unpack_int32+0x38>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1148 <unpack_int32+0x38>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1154 <unpack_int32+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <unpack_int32+0x85>
mov    -0x20(%rbp),%rcx
mov    $0x4,%eax
cmp    (%rcx),%eax
jle    1171 <unpack_int32+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <unpack_int32+0x85>
mov    -0x20(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <ntohl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_int32>:
push   %rbx
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     113e <unpack_int32+0x2e>
mov    %rsi,%rbx
test   %rsi,%rsi
je     113e <unpack_int32+0x2e>
test   %rdx,%rdx
je     113e <unpack_int32+0x2e>
cmpl   $0x4,(%rdx)
jl     113e <unpack_int32+0x2e>
movl   $0x4,(%rdx)
mov    (%rdi),%edi
call   1030 <ntohl@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @unpack_int32(i32* %0, i32* writeonly %1, i32* %2) {
%4 = icmp eq i32* %0, null
%5 = icmp eq i32* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i32* %2, null
%8 = or i1 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 4
br i1 %11, label %15, label %12
12: ; preds = %9
store i32 4, i32* %2
%13 = load i32, i32* %0
%14 = tail call i32 @ntohl(i32 %13)
store i32 %14, i32* %1
br label %15
15: ; preds = %9, %3, %12
%16 = phi i32 [ 0, %12 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %16
}