#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 *OPENSSL_hexstr2buf(char const *, long *);
unsigned char *OPENSSL_malloc(int);
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
int /*<<< orphan*/ test_info(char *, int, char *, char const *);
int /*<<< orphan*/ test_openssl_errors();
int /*<<< orphan*/ test_ptr(char *, int, char *, unsigned char *);
unsigned char *unescape(char const *, size_t, size_t *);
int parse_bin(const char *value, unsigned char **buf, size_t *buflen) {
  long len;
  if (strcmp(value, "NULL") == 0) {
    *buf = NULL;
    *buflen = 0;
    return 1;
  }
  if (*value == '\0') {
    *buf = OPENSSL_malloc(1);
    if (*buf == NULL)
      return 0;
    **buf = 0;
    *buflen = 0;
    return 1;
  }
  if (value[0] == '"') {
    size_t vlen = strlen(++value);
    if (vlen == 0 || value[vlen - 1] != '"')
      return 0;
    vlen--;
    *buf = unescape(value, vlen, buflen);
    return *buf == NULL ? 0 : 1;
  }
  if (!test_ptr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/"
                "refs/heads/master/Src/OSF/OpenSSL-111/test/evp_test.c",
                305, "*buf = OPENSSL_hexstr2buf(value, &len)",
                *buf = OPENSSL_hexstr2buf(value, &len))) {
    test_info("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/"
              "heads/master/Src/OSF/OpenSSL-111/test/evp_test.c",
              306, "Can't convert %s", value);
    test_openssl_errors();
    return -1;
  }
  *buflen = len;
  return 1;
}


x86 assembly (clang, -O0):
<parse_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d0 <parse_bin+0x50>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    122f <parse_bin+0xaf>
mov    $0x1,%edi
call   1070 <OPENSSL_malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    120e <parse_bin+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    12c8 <parse_bin+0x148>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x10(%rbp)
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1278 <parse_bin+0xf8>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
je     1284 <parse_bin+0x104>
movl   $0x0,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <unescape@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <OPENSSL_hexstr2buf@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    0xd1f(%rip),%rdi
mov    $0x131,%esi
lea    0xdbf(%rip),%rdx
call   1040 <test_ptr@plt>
cmp    $0x0,%eax
jne    132f <parse_bin+0x1af>
mov    -0x10(%rbp),%rcx
lea    0xcfa(%rip),%rdi
mov    $0x132,%esi
lea    0xdc1(%rip),%rdx
call   1090 <test_info@plt>
mov    $0x0,%al
call   10a0 <test_openssl_errors@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <parse_bin+0x1c1>
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):
<parse_bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe64(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11da <parse_bin+0x5a>
mov    (%rbx),%al
cmp    $0x22,%al
je     11ea <parse_bin+0x6a>
test   %al,%al
jne    1223 <parse_bin+0xa3>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1070 <OPENSSL_malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     126e <parse_bin+0xee>
movb   $0x0,(%rax)
movq   $0x0,(%r14)
jmp    125f <parse_bin+0xdf>
movq   $0x0,(%r15)
movq   $0x0,(%r14)
jmp    125a <parse_bin+0xda>
lea    0x1(%rbx),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     125f <parse_bin+0xdf>
cmpb   $0x22,(%rbx,%rax,1)
jne    125f <parse_bin+0xdf>
add    $0xffffffffffffffff,%rax
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1080 <unescape@plt>
mov    %rax,(%r15)
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    125f <parse_bin+0xdf>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <OPENSSL_hexstr2buf@plt>
mov    %rax,(%r15)
lea    0xdcb(%rip),%rdi
lea    0xe70(%rip),%rdx
mov    $0x131,%esi
mov    %rax,%rcx
call   1040 <test_ptr@plt>
test   %eax,%eax
je     1272 <parse_bin+0xf2>
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    125f <parse_bin+0xdf>
lea    0xd8c(%rip),%rdi
lea    0xe58(%rip),%rdx
mov    $0x132,%esi
mov    %rbx,%rcx
call   1090 <test_info@plt>
xor    %eax,%eax
call   10a0 <test_openssl_errors@plt>
mov    $0xffffffff,%ebp
jmp    125f <parse_bin+0xdf>

LLVM IR (-O0):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [172 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/evp_test.c\00"
@.str.2 = [39 x i8] c"*buf = OPENSSL_hexstr2buf(value, &len)\00"
@.str.3 = [17 x i8] c"Can't convert %s\00"
define i32 @parse_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 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8**, i8*** %6
store i8* null, i8** %14
%15 = load i64*, i64** %7
store i64 0, i64* %15
store i32 1, i32* %4
br label %79
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = call i8* @OPENSSL_malloc(i32 1)
%23 = load i8**, i8*** %6
store i8* %22, i8** %23
%24 = load i8**, i8*** %6
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 0, i32* %4
br label %79
28: ; preds = %21
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
store i8 0, i8* %30
%31 = load i64*, i64** %7
store i64 0, i64* %31
store i32 1, i32* %4
br label %79
32: ; preds = %16
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 34
br i1 %37, label %38, label %66
38: ; preds = %32
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
%41 = call i64 @strlen(i8* %40)
store i64 %41, i64* %9
%42 = load i64, i64* %9
%43 = icmp eq i64 %42, 0
br i1 %43, label %52, label %44
44: ; preds = %38
%45 = load i8*, i8** %5
%46 = load i64, i64* %9
%47 = sub i64 %46, 1
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 34
br i1 %51, label %52, label %53
52: ; preds = %44, %38
store i32 0, i32* %4
br label %79
53: ; preds = %44
%54 = load i64, i64* %9
%55 = add i64 %54, -1
store i64 %55, i64* %9
%56 = load i8*, i8** %5
%57 = load i64, i64* %9
%58 = load i64*, i64** %7
%59 = call i8* @unescape(i8* %56, i64 %57, i64* %58)
%60 = load i8**, i8*** %6
store i8* %59, i8** %60
%61 = load i8**, i8*** %6
%62 = load i8*, i8** %61
%63 = icmp eq i8* %62, null
%64 = zext i1 %63 to i64
%65 = select i1 %63, i32 0, i32 1
store i32 %65, i32* %4
br label %79
66: ; preds = %32
%67 = load i8*, i8** %5
%68 = call i8* @OPENSSL_hexstr2buf(i8* %67, i64* %8)
%69 = load i8**, i8*** %6
store i8* %68, i8** %69
%70 = call i32 @test_ptr(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.1, i64 0, i64 0), i32 305, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %68)
%71 = icmp ne i32 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %66
%73 = load i8*, i8** %5
%74 = call i32 @test_info(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.1, i64 0, i64 0), i32 306, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %73)
%75 = call i32 (...) @test_openssl_errors()
store i32 -1, i32* %4
br label %79
76: ; preds = %66
%77 = load i64, i64* %8
%78 = load i64*, i64** %7
store i64 %77, i64* %78
store i32 1, i32* %4
br label %79
79: ; preds = %76, %72, %53, %52, %28, %27, %13
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [172 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/evp_test.c\00"
@.str.2 = [39 x i8] c"*buf = OPENSSL_hexstr2buf(value, &len)\00"
@.str.3 = [17 x i8] c"Can't convert %s\00"
define i32 @parse_bin(i8* %0, i8** nocapture writeonly %1, i64* %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
store i8* null, i8** %1
store i64 0, i64* %2
br label %37
9: ; preds = %3
%10 = load i8, i8* %0
switch i8 %10, label %28 [
i8 0, label %11
i8 34, label %15
]
11: ; preds = %9
%12 = tail call i8* @OPENSSL_malloc(i32 1)
store i8* %12, i8** %1
%13 = icmp eq i8* %12, null
br i1 %13, label %37, label %14
14: ; preds = %11
store i8 0, i8* %12
store i64 0, i64* %2
br label %37
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = tail call i64 @strlen(i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %0, i64 %17
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 34
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = add i64 %17, -1
%25 = tail call i8* @unescape(i8* %16, i64 %24, i64* %2)
store i8* %25, i8** %1
%26 = icmp ne i8* %25, null
%27 = zext i1 %26 to i32
br label %37
28: ; preds = %9
%29 = call i8* @OPENSSL_hexstr2buf(i8* %0, i64* %4)
store i8* %29, i8** %1
%30 = call i32 @test_ptr(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.1, i64 0, i64 0), i32 305, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @test_info(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.1, i64 0, i64 0), i32 306, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%34 = call i32 (...) @test_openssl_errors()
br label %37
35: ; preds = %28
%36 = load i64, i64* %4
store i64 %36, i64* %2
br label %37
37: ; preds = %23, %19, %15, %11, %35, %32, %14, %8
%38 = phi i32 [ 1, %8 ], [ 1, %14 ], [ 1, %35 ], [ -1, %32 ], [ 0, %11 ], [ %27, %23 ], [ 0, %19 ], [ 0, %15 ]
ret i32 %38
}