#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 */
struct reader {
  int dummy;
};

/* Variables and functions */
long fullread(struct reader *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int stream_read_frame_body(struct reader *rds, unsigned char *buf, int size) {
  long l;
  if ((l = fullread(rds, buf, size)) != size) {
    if (l <= 0)
      return 0;
    memset(buf + l, 0, size - l);
  }
  return 1;
}


x86 assembly (clang, -O0):
<stream_read_frame_body>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <fullread@plt>
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
je     1184 <stream_read_frame_body+0x64>
cmpq   $0x0,-0x28(%rbp)
jg     116b <stream_read_frame_body+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    118b <stream_read_frame_body+0x6b>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stream_read_frame_body>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
call   1030 <fullread@plt>
movslq %ebp,%rcx
mov    $0x1,%r14d
cmp    %rcx,%rax
je     1157 <stream_read_frame_body+0x37>
test   %rax,%rax
jle    1154 <stream_read_frame_body+0x34>
add    %rax,%rbx
sub    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
jmp    1157 <stream_read_frame_body+0x37>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.reader = type { i32 }
define i32 @stream_read_frame_body(%struct.reader* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.reader*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store %struct.reader* %0, %struct.reader** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load %struct.reader*, %struct.reader** %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i64 @fullread(%struct.reader* %9, i8* %10, i32 %11)
store i64 %12, i64* %8
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = icmp ne i64 %12, %14
br i1 %15, label %16, label %30
16: ; preds = %3
%17 = load i64, i64* %8
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 0, i32* %4
br label %31
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = load i64, i64* %8
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = load i64, i64* %8
%27 = sub nsw i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @memset(i8* %23, i32 0, i32 %28)
br label %30
30: ; preds = %20, %3
store i32 1, i32* %4
br label %31
31: ; preds = %30, %19
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.reader = type { i32 }
define i32 @stream_read_frame_body(%struct.reader* %0, i8* %1, i32 %2) {
%4 = tail call i64 @fullread(%struct.reader* %0, i8* %1, i32 %2)
%5 = sext i32 %2 to i64
%6 = icmp eq i64 %4, %5
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = icmp slt i64 %4, 1
br i1 %8, label %14, label %9
9: ; preds = %7
%10 = getelementptr inbounds i8, i8* %1, i64 %4
%11 = trunc i64 %4 to i32
%12 = sub i32 %2, %11
%13 = tail call i32 @memset(i8* %10, i32 0, i32 %12)
br label %14
14: ; preds = %3, %9, %7
%15 = phi i32 [ 0, %7 ], [ 1, %9 ], [ 1, %3 ]
ret i32 %15
}