#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char convert_to_hex_value(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ isxdigit(char);
scalar_t__ malloc(int);
scalar_t__ realloc(unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
unsigned char *convert_to_byte_string(FILE *file_in, int *size) {
  int comment_level = 0;
  int input_string_size = 4096;
  char input[input_string_size];
  int byte_buffer_size = 1024;
  int byte_buffer_offset = 0;
  unsigned char *byte_buffer =
      (unsigned char *)malloc(1024 * sizeof(*byte_buffer));
  if (byte_buffer == NULL) {
    return NULL;
  }
  while (fscanf(file_in, "%s", input) > 0) {
    if (!strcmp(input, "/*")) {
      comment_level++;
      continue;
    }
    if (!strcmp(input, "*/")) {
      if (comment_level <= 0) {
        fprintf(stderr, "Error: stray %s found.\n", "*/");
        free(byte_buffer);
        return NULL;
      }
      comment_level--;
      continue;
    }
    if (comment_level == 0) {
      if (!isxdigit(input[0]) || !isxdigit(input[1]) || (input[2] != '\0')) {
        fprintf(stderr,
                "Invalid hex value [%s]. "
                "Please specify only single byte hex values separated by "
                "whitespace.\n",
                input);
        free(byte_buffer);
        return NULL;
      }
      unsigned char b = convert_to_hex_value(input);
      if (byte_buffer_offset == byte_buffer_size) {
        byte_buffer =
            (unsigned char *)realloc(byte_buffer, 2 * byte_buffer_size);
        if (byte_buffer == NULL) {
          return NULL;
        }
        byte_buffer_size *= 2;
      }
      byte_buffer[byte_buffer_offset++] = b;
    }
  }
  *size = byte_buffer_offset;
  return byte_buffer;
}


x86 assembly (clang, -O0):
<convert_to_byte_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1000,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x400,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11ff <convert_to_byte_string+0x7f>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    13b7 <convert_to_byte_string+0x237>
jmp    1204 <convert_to_byte_string+0x84>
mov    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x0,%rax
jle    139f <convert_to_byte_string+0x21f>
mov    -0x50(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1249 <convert_to_byte_string+0xc9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <convert_to_byte_string+0x84>
mov    -0x50(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12b3 <convert_to_byte_string+0x133>
cmpl   $0x0,-0x1c(%rbp)
jg     12a5 <convert_to_byte_string+0x125>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
lea    0xd83(%rip),%rdx
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    13b7 <convert_to_byte_string+0x237>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <convert_to_byte_string+0x84>
cmpl   $0x0,-0x1c(%rbp)
jne    139a <convert_to_byte_string+0x21a>
mov    -0x50(%rbp),%rax
movsbl (%rax),%edi
call   10a0 <isxdigit@plt>
cmp    $0x0,%eax
je     12f9 <convert_to_byte_string+0x179>
mov    -0x50(%rbp),%rax
movsbl 0x1(%rax),%edi
call   10a0 <isxdigit@plt>
cmp    $0x0,%eax
je     12f9 <convert_to_byte_string+0x179>
mov    -0x50(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     132f <convert_to_byte_string+0x1af>
mov    -0x50(%rbp),%rdx
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    13b7 <convert_to_byte_string+0x237>
mov    -0x50(%rbp),%rdi
call   1030 <convert_to_hex_value@plt>
mov    %al,-0x45(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    1382 <convert_to_byte_string+0x202>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
shl    $0x1,%esi
call   1090 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1379 <convert_to_byte_string+0x1f9>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    13b7 <convert_to_byte_string+0x237>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x45(%rbp),%dl
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1204 <convert_to_byte_string+0x84>
mov    -0x38(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_byte_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
mov    $0x400,%edi
call   1070 <malloc@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1304 <convert_to_byte_string+0x194>
mov    %rax,0x8(%rsp)
lea    0xe57(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
test   %rax,%rax
mov    %rbp,0x18(%rsp)
jle    12d1 <convert_to_byte_string+0x161>
movl   $0x400,0x14(%rsp)
mov    $0x2a2f,%r13d
lea    0xe27(%rip),%rbx
lea    0x20(%rsp),%rbp
mov    $0x2f2a,%r15d
xor    %r12d,%r12d
movl   $0x0,0x4(%rsp)
jmp    122c <convert_to_byte_string+0xbc>
mov    0x8(%rsp),%rax
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %rax,0x8(%rsp)
mov    %r14b,(%rax,%rcx,1)
mov    $0x2a2f,%r13d
mov    %r15,%r14
mov    $0x2f2a,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
test   %rax,%rax
jle    12d1 <convert_to_byte_string+0x161>
mov    0x20(%rsp),%eax
xor    %r13d,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
je     12ae <convert_to_byte_string+0x13e>
mov    0x20(%rsp),%eax
xor    %r15d,%eax
movzbl 0x22(%rsp),%ecx
or     %ax,%cx
je     12b9 <convert_to_byte_string+0x149>
cmpl   $0x0,0x4(%rsp)
jne    1215 <convert_to_byte_string+0xa5>
movsbl 0x20(%rsp),%edi
call   1090 <isxdigit@plt>
test   %eax,%eax
je     12e0 <convert_to_byte_string+0x170>
movsbl 0x21(%rsp),%edi
call   1090 <isxdigit@plt>
test   %eax,%eax
je     12e0 <convert_to_byte_string+0x170>
cmpb   $0x0,0x22(%rsp)
jne    12e0 <convert_to_byte_string+0x170>
mov    %rbp,%rdi
mov    %r14,%r15
call   1030 <convert_to_hex_value@plt>
mov    %eax,%r14d
cmp    0x14(%rsp),%r12d
jne    11f1 <convert_to_byte_string+0x81>
lea    (%r12,%r12,1),%esi
mov    0x8(%rsp),%rdi
mov    %esi,0x14(%rsp)
call   1080 <realloc@plt>
test   %rax,%rax
jne    11f6 <convert_to_byte_string+0x86>
jmp    1304 <convert_to_byte_string+0x194>
mov    $0x1,%eax
mov    0x4(%rsp),%ecx
jmp    12c6 <convert_to_byte_string+0x156>
mov    $0xffffffff,%eax
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    1318 <convert_to_byte_string+0x1a8>
add    %eax,%ecx
mov    %ecx,0x4(%rsp)
jmp    1215 <convert_to_byte_string+0xa5>
mov    0x18(%rsp),%rax
mov    %r12d,(%rax)
mov    0x8(%rsp),%rax
jmp    1306 <convert_to_byte_string+0x196>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xce1(%rip),%rsi
lea    0xcd7(%rip),%rdx
jmp    12f5 <convert_to_byte_string+0x185>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"/*\00"
@.str.2 = [3 x i8] c"*/\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"Error: stray %s found.\0A\00"
@.str.4 = [93 x i8] c"Invalid hex value [%s]. Please specify only single byte hex values separated by whitespace.\0A\00"
define i8* @convert_to_byte_string(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 4096, i32* %7
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
store i32 1024, i32* %10
store i32 0, i32* %11
%19 = call i64 @malloc(i32 1024)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %12
%21 = load i8*, i8** %12
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %2
store i8* null, i8** %3
store i32 1, i32* %13
br label %101
24: ; preds = %2
br label %25
25: ; preds = %96, %46, %32, %24
%26 = load i32*, i32** %4
%27 = call i64 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %97
29: ; preds = %25
%30 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %25
35: ; preds = %29
%36 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %35
%39 = load i32, i32* %6
%40 = icmp sle i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %12
%45 = call i32 @free(i8* %44)
store i8* null, i8** %3
store i32 1, i32* %13
br label %101
46: ; preds = %38
%47 = load i32, i32* %6
%48 = add nsw i32 %47, -1
store i32 %48, i32* %6
br label %25
49: ; preds = %35
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %96
52: ; preds = %49
%53 = getelementptr inbounds i8, i8* %18, i64 0
%54 = load i8, i8* %53
%55 = call i32 @isxdigit(i8 signext %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %67
57: ; preds = %52
%58 = getelementptr inbounds i8, i8* %18, i64 1
%59 = load i8, i8* %58
%60 = call i32 @isxdigit(i8 signext %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = getelementptr inbounds i8, i8* %18, i64 2
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62, %57, %52
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%70 = load i8*, i8** %12
%71 = call i32 @free(i8* %70)
store i8* null, i8** %3
store i32 1, i32* %13
br label %101
72: ; preds = %62
%73 = call zeroext i8 @convert_to_hex_value(i8* %18)
store i8 %73, i8* %14
%74 = load i32, i32* %11
%75 = load i32, i32* %10
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %89
77: ; preds = %72
%78 = load i8*, i8** %12
%79 = load i32, i32* %10
%80 = mul nsw i32 2, %79
%81 = call i64 @realloc(i8* %78, i32 %80)
%82 = inttoptr i64 %81 to i8*
store i8* %82, i8** %12
%83 = load i8*, i8** %12
%84 = icmp eq i8* %83, null
br i1 %84, label %85, label %86
85: ; preds = %77
store i8* null, i8** %3
store i32 1, i32* %13
br label %101
86: ; preds = %77
%87 = load i32, i32* %10
%88 = mul nsw i32 %87, 2
store i32 %88, i32* %10
br label %89
89: ; preds = %86, %72
%90 = load i8, i8* %14
%91 = load i8*, i8** %12
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 1
store i32 %93, i32* %11
%94 = sext i32 %92 to i64
%95 = getelementptr inbounds i8, i8* %91, i64 %94
store i8 %90, i8* %95
br label %96
96: ; preds = %89, %49
br label %25
97: ; preds = %25
%98 = load i32, i32* %11
%99 = load i32*, i32** %5
store i32 %98, i32* %99
%100 = load i8*, i8** %12
store i8* %100, i8** %3
store i32 1, i32* %13
br label %101
101: ; preds = %97, %85, %67, %41, %23
%102 = load i8*, i8** %8
%103 = load i8*, i8** %3
ret i8* %103
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"/*\00"
@.str.2 = [3 x i8] c"*/\00"
@stderr = global i32 0
@.str.3 = [24 x i8] c"Error: stray %s found.\0A\00"
@.str.4 = [93 x i8] c"Invalid hex value [%s]. Please specify only single byte hex values separated by whitespace.\0A\00"
define i8* @convert_to_byte_string(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @malloc(i32 1024)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %80, label %8
8: ; preds = %2
%9 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %77
11: ; preds = %8
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 1
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 2
br label %14
14: ; preds = %11, %35
%15 = phi i8* [ %6, %11 ], [ %21, %35 ]
%16 = phi i32 [ 0, %11 ], [ %22, %35 ]
%17 = phi i32 [ 1024, %11 ], [ %23, %35 ]
%18 = phi i32 [ 0, %11 ], [ %37, %35 ]
%19 = icmp eq i32 %18, 0
br label %20
20: ; preds = %14, %71
%21 = phi i8* [ %15, %14 ], [ %74, %71 ]
%22 = phi i32 [ %16, %14 ], [ %73, %71 ]
%23 = phi i32 [ %17, %14 ], [ %72, %71 ]
%24 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %20
%27 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = icmp slt i32 %18, 1
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @free(i8* %21)
br label %80
35: ; preds = %20, %29
%36 = phi i32 [ -1, %29 ], [ 1, %20 ]
%37 = add nsw i32 %18, %36
%38 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %14, label %77
40: ; preds = %26
br i1 %19, label %41, label %71
41: ; preds = %40
%42 = load i8, i8* %4
%43 = call i32 @isxdigit(i8 signext %42)
%44 = icmp eq i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %41
%46 = load i8, i8* %12
%47 = call i32 @isxdigit(i8 signext %46)
%48 = icmp ne i32 %47, 0
%49 = load i8, i8* %13
%50 = icmp eq i8 %49, 0
%51 = select i1 %48, i1 %50, i1 false
br i1 %51, label %56, label %52
52: ; preds = %45, %41
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%55 = call i32 @free(i8* %21)
br label %80
56: ; preds = %45
%57 = call zeroext i8 @convert_to_hex_value(i8* %4)
%58 = icmp eq i32 %22, %23
br i1 %58, label %59, label %65
59: ; preds = %56
%60 = shl nsw i32 %22, 1
%61 = call i64 @realloc(i8* %21, i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %80, label %63
63: ; preds = %59
%64 = inttoptr i64 %61 to i8*
br label %65
65: ; preds = %56, %63
%66 = phi i32 [ %60, %63 ], [ %23, %56 ]
%67 = phi i8* [ %64, %63 ], [ %21, %56 ]
%68 = add nsw i32 %22, 1
%69 = sext i32 %22 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 %57, i8* %70
br label %71
71: ; preds = %65, %40
%72 = phi i32 [ %23, %40 ], [ %66, %65 ]
%73 = phi i32 [ %22, %40 ], [ %68, %65 ]
%74 = phi i8* [ %21, %40 ], [ %67, %65 ]
%75 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%76 = icmp sgt i64 %75, 0
br i1 %76, label %20, label %77
77: ; preds = %35, %71, %8
%78 = phi i32 [ 0, %8 ], [ %73, %71 ], [ %22, %35 ]
%79 = phi i8* [ %6, %8 ], [ %74, %71 ], [ %21, %35 ]
store i32 %78, i32* %1
br label %80
80: ; preds = %59, %2, %77, %52, %31
%81 = phi i8* [ null, %52 ], [ null, %31 ], [ %79, %77 ], [ null, %2 ], [ null, %59 ]
ret i8* %81
}