#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*/ exit(int);
int /*<<< orphan*/ file_write_b(char *, int *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ isalnum(char);
scalar_t__ isspace(char);
int *malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int strtol(char *, char **, int);
int hex_to_bin(char *o_file_name, char *i_buffer) {
  int l_buffer = strlen(i_buffer);
  int *o_buffer = NULL;
  char *p_end = NULL;
  int n_hex = 0;
  int is_same_number = 0;
  for (int k = 0; k < l_buffer; k++) {
    if (isalnum(i_buffer[k]) && is_same_number == 0) {
      n_hex++;
      is_same_number = 1;
    }
    while (isspace(i_buffer[k])) {
      k++;
      is_same_number = 0;
    }
  }
  o_buffer = malloc(sizeof(int) * (n_hex));
  if (o_buffer == NULL) {
    fputs("Memory error", stderr);
    exit(5);
  }
  o_buffer[0] = strtol(i_buffer, &p_end, 16);
  for (int i = 1; i < n_hex; i++) {
    o_buffer[i] = strtol(p_end, &p_end, 16);
  }
  file_write_b(o_file_name, o_buffer, n_hex);
  free(o_buffer);
  return 0;
}


x86 assembly (clang, -O0):
<hex_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125a <hex_to_bin+0xca>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
je     1212 <hex_to_bin+0x82>
cmpl   $0x0,-0x30(%rbp)
jne    1212 <hex_to_bin+0x82>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1217 <hex_to_bin+0x87>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     1247 <hex_to_bin+0xb7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
jmp    1217 <hex_to_bin+0x87>
jmp    124c <hex_to_bin+0xbc>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d1 <hex_to_bin+0x41>
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1297 <hex_to_bin+0x107>
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
lea    0xd78(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12f1 <hex_to_bin+0x161>
mov    -0x28(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12b8 <hex_to_bin+0x128>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10b0 <file_write_b@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
movq   $0x0,0x8(%rsp)
test   %eax,%eax
jle    1238 <hex_to_bin+0xa8>
mov    %eax,%r12d
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11df <hex_to_bin+0x4f>
nopl   0x0(%rax,%rax,1)
movzbl %r13b,%eax
add    %eax,%r15d
add    $0x1,%ebp
cmp    %r12d,%ebp
jge    123b <hex_to_bin+0xab>
movslq %ebp,%rbp
movsbl (%rbx,%rbp,1),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
setne  %al
test   %r14d,%r14d
sete   %r13b
and    %al,%r13b
mov    $0x1,%eax
cmovne %eax,%r14d
movsbl (%rbx,%rbp,1),%edi
call   1070 <isspace@plt>
test   %rax,%rax
je     11d0 <hex_to_bin+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x1(%rbx,%rbp,1),%edi
add    $0x1,%rbp
call   1070 <isspace@plt>
test   %rax,%rax
jne    1220 <hex_to_bin+0x90>
xor    %r14d,%r14d
jmp    11d0 <hex_to_bin+0x40>
xor    %r15d,%r15d
lea    0x0(,%r15,4),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12c8 <hex_to_bin+0x138>
mov    %rax,%r12
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,(%r12)
cmp    $0x2,%r15d
jb     129f <hex_to_bin+0x10f>
mov    %r15d,%ebx
mov    $0x1,%ebp
lea    0x8(%rsp),%r14
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,(%r12,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1280 <hex_to_bin+0xf0>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   10b0 <file_write_b@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
lea    0xd28(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"Memory error\00"
@stderr = global i32 0
define i32 @hex_to_bin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = tail call i32 @strlen(i8* %1)
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = icmp sgt i32 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %35, %2
%8 = phi i32 [ 0, %2 ], [ %38, %35 ]
%9 = shl i32 %8, 2
%10 = tail call i32* @malloc(i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %42, label %46
12: ; preds = %2, %35
%13 = phi i32 [ %40, %35 ], [ 0, %2 ]
%14 = phi i32 [ %36, %35 ], [ 0, %2 ]
%15 = phi i32 [ %38, %35 ], [ 0, %2 ]
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @isalnum(i8 signext %18)
%20 = icmp ne i64 %19, 0
%21 = icmp eq i32 %14, 0
%22 = select i1 %20, i1 %21, i1 false
%23 = zext i1 %22 to i32
%24 = select i1 %22, i32 1, i32 %14
%25 = load i8, i8* %17
%26 = tail call i64 @isspace(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %12, %28
%29 = phi i64 [ %30, %28 ], [ %16, %12 ]
%30 = add i64 %29, 1
%31 = getelementptr inbounds i8, i8* %1, i64 %30
%32 = load i8, i8* %31
%33 = tail call i64 @isspace(i8 signext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %28
35: ; preds = %28, %12
%36 = phi i32 [ %24, %12 ], [ 0, %28 ]
%37 = phi i64 [ %16, %12 ], [ %30, %28 ]
%38 = add nuw nsw i32 %15, %23
%39 = trunc i64 %37 to i32
%40 = add nsw i32 %39, 1
%41 = icmp slt i32 %40, %4
br i1 %41, label %12, label %7
42: ; preds = %7
%43 = load i32, i32* @stderr
%44 = tail call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = tail call i32 @exit(i32 5)
unreachable
46: ; preds = %7
%47 = call i32 @strtol(i8* %1, i8** %3, i32 16)
store i32 %47, i32* %10
%48 = icmp ugt i32 %8, 1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = zext i32 %8 to i64
br label %54
51: ; preds = %54, %46
%52 = tail call i32 @file_write_b(i8* %0, i32* %10, i32 %8)
%53 = tail call i32 @free(i32* %10)
ret i32 0
54: ; preds = %49, %54
%55 = phi i64 [ 1, %49 ], [ %59, %54 ]
%56 = load i8*, i8** %3
%57 = call i32 @strtol(i8* %56, i8** %3, i32 16)
%58 = getelementptr inbounds i32, i32* %10, i64 %55
store i32 %57, i32* %58
%59 = add nuw nsw i64 %55, 1
%60 = icmp eq i64 %59, %50
br i1 %60, label %51, label %54
}