#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*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void obfsem_keep_encode(void *in, size_t insiz, void **out, size_t *outsiz) {
  static void *buf = NULL;
  if (buf != NULL) {
    free(buf);
  }
  buf = malloc(insiz);
  memcpy(buf, in, insiz);
  *outsiz = insiz;
  *out = buf;
}


x86 assembly (clang, -O0):
<obfsem_keep_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,0x2ef0(%rip)
je     1162 <obfsem_keep_encode+0x32>
mov    0x2ee3(%rip),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,0x2ece(%rip)
mov    0x2ec7(%rip),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2ea8(%rip),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obfsem_keep_encode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    0x2ef5(%rip),%rdi
test   %rdi,%rdi
je     1155 <obfsem_keep_encode+0x25>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,0x2edc(%rip)
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %rbx,(%r15)
mov    0x2ec4(%rip),%rax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@obfsem_keep_encode.buf = internal global i8* null
define void @obfsem_keep_encode(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
store i64* %3, i64** %8
%9 = load i8*, i8** @obfsem_keep_encode.buf
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i8*, i8** @obfsem_keep_encode.buf
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %4
%15 = load i64, i64* %6
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** @obfsem_keep_encode.buf
%17 = load i8*, i8** @obfsem_keep_encode.buf
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = call i32 @memcpy(i8* %17, i8* %18, i64 %19)
%21 = load i64, i64* %6
%22 = load i64*, i64** %8
store i64 %21, i64* %22
%23 = load i8*, i8** @obfsem_keep_encode.buf
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
ret void
}

LLVM IR (-O2):
@obfsem_keep_encode.buf = internal unnamed_addr global i8* null
define void @obfsem_keep_encode(i8* %0, i64 %1, i8** nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = load i8*, i8** @obfsem_keep_encode.buf
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @free(i8* %5)
br label %9
9: ; preds = %7, %4
%10 = tail call i8* @malloc(i64 %1)
store i8* %10, i8** @obfsem_keep_encode.buf
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i64 %1)
store i64 %1, i64* %3
%12 = load i8*, i8** @obfsem_keep_encode.buf
store i8* %12, i8** %2
ret void
}