#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 */
unsigned char *BUF_memdup(char const *, size_t);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
unsigned char *OPENSSL_malloc(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned char *string_to_hex(char const *, long *);
size_t strlen(char const *);
int test_bin(const char *value, unsigned char **buf, size_t *buflen) {
  long len;
  if (!*value) {
    *buf = OPENSSL_malloc(1);
    if (!*buf)
      return 0;
    **buf = 0;
    *buflen = 0;
    return 1;
  }
  if (value[0] == '"') {
    size_t vlen;
    value++;
    vlen = strlen(value);
    if (value[vlen - 1] != '"')
      return 0;
    vlen--;
    if (vlen == 0) {
      *buf = OPENSSL_malloc(1);
      if (*buf == NULL)
        return 0;
      **buf = 0;
    } else {
      *buf = BUF_memdup(value, vlen);
      if (*buf == NULL)
        return 0;
    }
    *buflen = vlen;
    return 1;
  }
  *buf = string_to_hex(value, &len);
  if (!*buf) {
    fprintf(stderr, "Value=%s\n", value);
    ERR_print_errors_fp(stderr);
    return -1;
  }
  *buflen = len;
  return 1;
}


x86 assembly (clang, -O0):
<test_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11d0 <test_bin+0x70>
mov    $0x1,%edi
call   1060 <OPENSSL_malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11af <test_bin+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    12bf <test_bin+0x15f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
je     121e <test_bin+0xbe>
movl   $0x0,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1272 <test_bin+0x112>
mov    $0x1,%edi
call   1060 <OPENSSL_malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1263 <test_bin+0x103>
movl   $0x0,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
jmp    12a8 <test_bin+0x148>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <BUF_memdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12a3 <test_bin+0x143>
movl   $0x0,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
jmp    12a8 <test_bin+0x148>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <string_to_hex@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1317 <test_bin+0x1b7>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd08(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   1080 <ERR_print_errors_fp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <test_bin+0x1c9>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x22,%al
je     11a5 <test_bin+0x45>
test   %al,%al
jne    11db <test_bin+0x7b>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1060 <OPENSSL_malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11fd <test_bin+0x9d>
movb   $0x0,(%rax)
movq   $0x0,(%r14)
jmp    1227 <test_bin+0xc7>
lea    0x1(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmpb   $0x22,(%rbx,%rax,1)
jne    1227 <test_bin+0xc7>
mov    %rax,%r15
add    $0xffffffffffffffff,%r15
je     1238 <test_bin+0xd8>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <BUF_memdup@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1227 <test_bin+0xc7>
mov    %r15,(%r14)
jmp    11f6 <test_bin+0x96>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <string_to_hex@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1201 <test_bin+0xa1>
mov    (%rsp),%rax
mov    %rax,(%r14)
mov    $0x1,%ebp
jmp    1227 <test_bin+0xc7>
xor    %ebp,%ebp
jmp    1227 <test_bin+0xc7>
mov    0x2dd8(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdee(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1080 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1060 <OPENSSL_malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1227 <test_bin+0xc7>
movb   $0x0,(%rax)
mov    %r15,(%r14)
jmp    11f6 <test_bin+0x96>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [10 x i8] c"Value=%s\0A\00"
define i32 @test_bin(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %3
%14 = call i8* @OPENSSL_malloc(i32 1)
%15 = load i8**, i8*** %6
store i8* %14, i8** %15
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %87
20: ; preds = %13
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
store i8 0, i8* %22
%23 = load i64*, i64** %7
store i64 0, i64* %23
store i32 1, i32* %4
br label %87
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 34
br i1 %29, label %30, label %71
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = call i64 @strlen(i8* %33)
store i64 %34, i64* %9
%35 = load i8*, i8** %5
%36 = load i64, i64* %9
%37 = sub i64 %36, 1
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 34
br i1 %41, label %42, label %43
42: ; preds = %30
store i32 0, i32* %4
br label %87
43: ; preds = %30
%44 = load i64, i64* %9
%45 = add i64 %44, -1
store i64 %45, i64* %9
%46 = load i64, i64* %9
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %43
%49 = call i8* @OPENSSL_malloc(i32 1)
%50 = load i8**, i8*** %6
store i8* %49, i8** %50
%51 = load i8**, i8*** %6
%52 = load i8*, i8** %51
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %55
54: ; preds = %48
store i32 0, i32* %4
br label %87
55: ; preds = %48
%56 = load i8**, i8*** %6
%57 = load i8*, i8** %56
store i8 0, i8* %57
br label %68
58: ; preds = %43
%59 = load i8*, i8** %5
%60 = load i64, i64* %9
%61 = call i8* @BUF_memdup(i8* %59, i64 %60)
%62 = load i8**, i8*** %6
store i8* %61, i8** %62
%63 = load i8**, i8*** %6
%64 = load i8*, i8** %63
%65 = icmp eq i8* %64, null
br i1 %65, label %66, label %67
66: ; preds = %58
store i32 0, i32* %4
br label %87
67: ; preds = %58
br label %68
68: ; preds = %67, %55
%69 = load i64, i64* %9
%70 = load i64*, i64** %7
store i64 %69, i64* %70
store i32 1, i32* %4
br label %87
71: ; preds = %24
%72 = load i8*, i8** %5
%73 = call i8* @string_to_hex(i8* %72, i64* %8)
%74 = load i8**, i8*** %6
store i8* %73, i8** %74
%75 = load i8**, i8*** %6
%76 = load i8*, i8** %75
%77 = icmp ne i8* %76, null
br i1 %77, label %84, label %78
78: ; preds = %71
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %5
%81 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @stderr
%83 = call i32 @ERR_print_errors_fp(i32 %82)
store i32 -1, i32* %4
br label %87
84: ; preds = %71
%85 = load i64, i64* %8
%86 = load i64*, i64** %7
store i64 %85, i64* %86
store i32 1, i32* %4
br label %87
87: ; preds = %84, %78, %68, %66, %54, %42, %20, %19
%88 = load i32, i32* %4
ret i32 %88
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [10 x i8] c"Value=%s\0A\00"
define i32 @test_bin(i8* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = load i8, i8* %0
switch i8 %6, label %28 [
i8 0, label %7
i8 34, label %11
]
7: ; preds = %3
%8 = tail call i8* @OPENSSL_malloc(i32 1)
store i8* %8, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %38, label %10
10: ; preds = %7
store i8 0, i8* %8
store i64 0, i64* %2
br label %38
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = tail call i64 @strlen(i8* %12)
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 34
br i1 %16, label %17, label %38
17: ; preds = %11
%18 = add i64 %13, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = tail call i8* @OPENSSL_malloc(i32 1)
store i8* %21, i8** %1
%22 = icmp eq i8* %21, null
br i1 %22, label %38, label %23
23: ; preds = %20
store i8 0, i8* %21
br label %27
24: ; preds = %17
%25 = tail call i8* @BUF_memdup(i8* %12, i64 %18)
store i8* %25, i8** %1
%26 = icmp eq i8* %25, null
br i1 %26, label %38, label %27
27: ; preds = %24, %23
store i64 %18, i64* %2
br label %38
28: ; preds = %3
%29 = call i8* @string_to_hex(i8* %0, i64* %4)
store i8* %29, i8** %1
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%34 = load i32, i32* @stderr
%35 = call i32 @ERR_print_errors_fp(i32 %34)
br label %38
36: ; preds = %28
%37 = load i64, i64* %4
store i64 %37, i64* %2
br label %38
38: ; preds = %27, %11, %20, %24, %7, %36, %31, %10
%39 = phi i32 [ 1, %36 ], [ -1, %31 ], [ 1, %10 ], [ 0, %7 ], [ 1, %27 ], [ 0, %11 ], [ 0, %20 ], [ 0, %24 ]
ret i32 %39
}