#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int RTP_process(void **, size_t *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ buf_overrun(void *, size_t, int /*<<< orphan*/, size_t,
                               int /*<<< orphan*/ *);
int write_buf(int, void *, size_t, int /*<<< orphan*/ *);
ssize_t write_rtp2ts(int fd, const char *data, size_t len, FILE *log) {
  void *buf = (void *)data;
  size_t pldlen = len;
  const int NO_VERIFY = 0;
  int rc = 0;
  assert((fd > 0) && data && len && log);
  rc = RTP_process(&buf, &pldlen, NO_VERIFY, log);
  if (-1 == rc)
    return -1;
  assert(!buf_overrun(buf, len, 0, pldlen, log));
  return write_buf(fd, buf, pldlen, log);
}


x86 assembly (clang, -O0):
<write_rtp2ts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x39(%rbp)
jle    11af <write_rtp2ts+0x6f>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x39(%rbp)
je     11af <write_rtp2ts+0x6f>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x39(%rbp)
je     11af <write_rtp2ts+0x6f>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <RTP_process@plt>
mov    %eax,-0x38(%rbp)
mov    $0xffffffff,%eax
cmp    -0x38(%rbp),%eax
jne    11ec <write_rtp2ts+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <write_rtp2ts+0xec>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %edx,%edx
call   1040 <buf_overrun@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <write_buf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_rtp2ts>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %edi,%r14d
mov    %rsi,0x8(%rsp)
mov    %rdx,(%rsp)
test   %edi,%edi
setg   %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
test   %rdx,%rdx
setne  %al
test   %rbx,%rbx
setne  %dl
and    %al,%dl
and    %cl,%dl
movzbl %dl,%edi
call   1030 <assert@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
mov    %rbx,%rcx
call   1050 <RTP_process@plt>
cmp    $0xffffffff,%eax
je     11cf <write_rtp2ts+0x8f>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rcx
mov    %rbp,%rsi
xor    %edx,%edx
mov    %rbx,%r8
call   1040 <buf_overrun@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %r14d,%edi
mov    %rbx,%rcx
call   1060 <write_buf@plt>
jmp    11d4 <write_rtp2ts+0x94>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_rtp2ts(i32 %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%14 = load i8*, i8** %7
store i8* %14, i8** %10
%15 = load i64, i64* %8
store i64 %15, i64* %11
store i32 0, i32* %12
store i32 0, i32* %13
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64, i64* %8
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32*, i32** %9
%26 = icmp ne i32* %25, null
br label %27
27: ; preds = %24, %21, %18, %4
%28 = phi i1 [ false, %21 ], [ false, %18 ], [ false, %4 ], [ %26, %24 ]
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32*, i32** %9
%32 = call i32 @RTP_process(i8** %10, i64* %11, i32 0, i32* %31)
store i32 %32, i32* %13
%33 = load i32, i32* %13
%34 = icmp eq i32 -1, %33
br i1 %34, label %35, label %36
35: ; preds = %27
store i32 -1, i32* %5
br label %51
36: ; preds = %27
%37 = load i8*, i8** %10
%38 = load i64, i64* %8
%39 = load i64, i64* %11
%40 = load i32*, i32** %9
%41 = call i32 @buf_overrun(i8* %37, i64 %38, i32 0, i64 %39, i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %6
%47 = load i8*, i8** %10
%48 = load i64, i64* %11
%49 = load i32*, i32** %9
%50 = call i32 @write_buf(i32 %46, i8* %47, i64 %48, i32* %49)
store i32 %50, i32* %5
br label %51
51: ; preds = %36, %35
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @write_rtp2ts(i32 %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
store i8* %1, i8** %5
%8 = bitcast i64* %6 to i8*
store i64 %2, i64* %6
%9 = icmp sgt i32 %0, 0
%10 = icmp ne i8* %1, null
%11 = and i1 %9, %10
%12 = icmp ne i64 %2, 0
%13 = and i1 %11, %12
%14 = icmp ne i32* %3, null
%15 = and i1 %13, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = call i32 @RTP_process(i8** %5, i64* %6, i32 0, i32* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %30, label %20
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = call i32 @buf_overrun(i8* %21, i64 %2, i32 0, i64 %22, i32* %3)
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = call i32 @write_buf(i32 %0, i8* %27, i64 %28, i32* %3)
br label %30
30: ; preds = %4, %20
%31 = phi i32 [ %29, %20 ], [ -1, %4 ]
ret i32 %31
}