#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*/ writeSwap(void **, void const *, unsigned int);
int putStream(unsigned char **p, const void *dat, unsigned int lendat,
              unsigned char *peos) {
  ;
  if ((peos < *p) || (peos - *p < lendat)) {
    ;
    return -1;
  }
  if (lendat)
    writeSwap((void **)p, dat, lendat);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<putStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jb     1152 <putStream+0x42>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    -0x1c(%rbp),%ecx
cmp    %rcx,%rax
jge    115e <putStream+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <putStream+0x6f>
cmpl   $0x0,-0x1c(%rbp)
je     1178 <putStream+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <writeSwap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putStream>:
push   %rbx
mov    $0xffffffff,%ebx
sub    (%rdi),%rcx
jb     112d <putStream+0x1d>
mov    %edx,%eax
cmp    %rax,%rcx
jl     112d <putStream+0x1d>
xor    %ebx,%ebx
test   %edx,%edx
je     112d <putStream+0x1d>
call   1030 <writeSwap@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @putStream(i8** %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%10 = load i8*, i8** %9
%11 = load i8**, i8*** %6
%12 = load i8*, i8** %11
%13 = icmp ult i8* %10, %12
br i1 %13, label %24, label %14
14: ; preds = %4
%15 = load i8*, i8** %9
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = ptrtoint i8* %15 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %14, %4
store i32 -1, i32* %5
br label %34
25: ; preds = %14
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = call i32 @writeSwap(i8** %29, i8* %30, i32 %31)
br label %33
33: ; preds = %28, %25
store i32 0, i32* %5
br label %34
34: ; preds = %33, %24
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @putStream(i8** %0, i8* %1, i32 %2, i8* %3) {
%5 = load i8*, i8** %0
%6 = icmp ugt i8* %5, %3
%7 = ptrtoint i8* %3 to i64
%8 = ptrtoint i8* %5 to i64
%9 = sub i64 %7, %8
%10 = zext i32 %2 to i64
%11 = icmp slt i64 %9, %10
%12 = select i1 %6, i1 true, i1 %11
br i1 %12, label %17, label %13
13: ; preds = %4
%14 = icmp eq i32 %2, 0
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @writeSwap(i8** %0, i8* %1, i32 %2)
br label %17
17: ; preds = %13, %15, %4
%18 = phi i32 [ -1, %4 ], [ 0, %15 ], [ 0, %13 ]
ret i32 %18
}