#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 cb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cb_append(struct cb *, char const *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void frame_callback(const char *data, size_t len, void *userdata) {
  struct cb *cb = userdata;
  if (data && len && cb) {
    cb_append(cb, data, len);
    fprintf(stderr, "Image decoded (decoded len: %ld)\n", len);
  } else {
    fprintf(stderr, "ERROR decoding image\n");
  }
}


x86 assembly (clang, -O0):
<frame_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118e <frame_callback+0x6e>
cmpq   $0x0,-0x10(%rbp)
je     118e <frame_callback+0x6e>
cmpq   $0x0,-0x20(%rbp)
je     118e <frame_callback+0x6e>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <cb_append@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11a5 <frame_callback+0x85>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frame_callback>:
push   %rbx
test   %rdi,%rdi
je     115c <frame_callback+0x3c>
mov    %rsi,%rbx
test   %rsi,%rsi
je     115c <frame_callback+0x3c>
test   %rdx,%rdx
je     115c <frame_callback+0x3c>
mov    %rdi,%rsi
mov    %rdx,%rdi
mov    %rbx,%rdx
call   1030 <cb_append@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
pop    %rbx
jmp    1040 <fprintf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
xor    %eax,%eax
pop    %rbx
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.cb = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"Image decoded (decoded len: %ld)\0A\00"
@.str.1 = [22 x i8] c"ERROR decoding image\0A\00"
define void @frame_callback(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca %struct.cb*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = bitcast i8* %8 to %struct.cb*
store %struct.cb* %9, %struct.cb** %7
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %26
12: ; preds = %3
%13 = load i64, i64* %5
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load %struct.cb*, %struct.cb** %7
%17 = icmp ne %struct.cb* %16, null
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load %struct.cb*, %struct.cb** %7
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = call i32 @cb_append(%struct.cb* %19, i8* %20, i64 %21)
%23 = load i32, i32* @stderr
%24 = load i64, i64* %5
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %24)
br label %29
26: ; preds = %15, %12, %3
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %18
ret void
}

LLVM IR (-O2):
%struct.cb = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"Image decoded (decoded len: %ld)\0A\00"
@.str.1 = [22 x i8] c"ERROR decoding image\0A\00"
define void @frame_callback(i8* %0, i64 %1, i8* %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
%7 = icmp ne i8* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = bitcast i8* %2 to %struct.cb*
%11 = tail call i32 @cb_append(%struct.cb* %10, i8* %0, i64 %1)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %9
ret void
}