#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 char uint8_t;
struct user_data {
  int dummy;
};
struct sslbuffer_t {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ printf(char *, char *);
void sslreadcb(struct sslbuffer_t *sslbuffer, uint8_t *data, size_t size,
               void *ctx) {
  struct user_data *user_data;
  uint8_t buffer[256];
  size_t bufsize;
  uint8_t *srcdata;
  user_data = (struct user_data *)ctx;
  srcdata = (uint8_t *)data;
  while (size > 0) {
    bufsize = size;
    if (bufsize + 1 > sizeof(buffer))
      bufsize = sizeof(buffer) - 1;
    memcpy(buffer, srcdata, bufsize);
    buffer[bufsize] = '\0';
    printf("%s", buffer);
    size -= bufsize;
    srcdata += bufsize;
  }
}


x86 assembly (clang, -O0):
<sslreadcb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11ee <sslreadcb+0xce>
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
cmp    $0x100,%rax
jbe    1186 <sslreadcb+0x66>
movq   $0xff,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    -0x138(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x138(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x138(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x138(%rbp),%rax
add    -0x140(%rbp),%rax
mov    %rax,-0x140(%rbp)
jmp    114e <sslreadcb+0x2e>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sslreadcb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
test   %rdx,%rdx
je     1189 <sslreadcb+0x69>
mov    %rdx,%r13
mov    %rsi,%r14
mov    $0xff,%ebp
mov    %rsp,%r15
lea    0xeb5(%rip),%r12
nopl   0x0(%rax,%rax,1)
lea    -0x100(%r13),%rax
cmp    $0xfffffffffffffeff,%rax
mov    %r13,%rbx
cmovb  %rbp,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
add    %rbx,%r14
sub    %rbx,%r13
jne    1150 <sslreadcb+0x30>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sslbuffer_t = type { i32 }
%struct.user_data = type { i32 }
@.str = [3 x i8] c"%s\00"
define void @sslreadcb(%struct.sslbuffer_t* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca %struct.sslbuffer_t*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca %struct.user_data*
%10 = alloca [256 x i8]
%11 = alloca i64
%12 = alloca i8*
store %struct.sslbuffer_t* %0, %struct.sslbuffer_t** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%13 = load i8*, i8** %8
%14 = bitcast i8* %13 to %struct.user_data*
store %struct.user_data* %14, %struct.user_data** %9
%15 = load i8*, i8** %6
store i8* %15, i8** %12
br label %16
16: ; preds = %25, %4
%17 = load i64, i64* %7
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %16
%20 = load i64, i64* %7
store i64 %20, i64* %11
%21 = load i64, i64* %11
%22 = add i64 %21, 1
%23 = icmp ugt i64 %22, 256
br i1 %23, label %24, label %25
24: ; preds = %19
store i64 255, i64* %11
br label %25
25: ; preds = %24, %19
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%27 = load i8*, i8** %12
%28 = load i64, i64* %11
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
%30 = load i64, i64* %11
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i64, i64* %11
%35 = load i64, i64* %7
%36 = sub i64 %35, %34
store i64 %36, i64* %7
%37 = load i64, i64* %11
%38 = load i8*, i8** %12
%39 = getelementptr inbounds i8, i8* %38, i64 %37
store i8* %39, i8** %12
br label %16
40: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.sslbuffer_t = type { i32 }
@.str = [3 x i8] c"%s\00"
define void @sslreadcb(%struct.sslbuffer_t* nocapture readnone %0, i8* %1, i64 %2, i8* nocapture readnone %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = icmp eq i64 %2, 0
br i1 %7, label %20, label %8
8: ; preds = %4, %8
%9 = phi i8* [ %18, %8 ], [ %1, %4 ]
%10 = phi i64 [ %17, %8 ], [ %2, %4 ]
%11 = add i64 %10, -256
%12 = icmp ult i64 %11, -257
%13 = select i1 %12, i64 255, i64 %10
%14 = call i32 @memcpy(i8* %6, i8* %9, i64 %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %13
store i8 0, i8* %15
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%17 = sub i64 %10, %13
%18 = getelementptr inbounds i8, i8* %9, i64 %13
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %8
20: ; preds = %8, %4
ret void
}