#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 byte_from_hex_str(char *);
int strlen(char const *);
int bytes_from_hex_string(unsigned char *out_bytes, const char *hex_string) {
  if (0 != strlen(hex_string) % 2)
    return 1;
  int i = 0;
  int outbyte_counter = 0;
  int len = strlen(hex_string);
  for (i = 0; i < len; i += 2) {
    char hex_string_piece[2] = "";
    hex_string_piece[0] = *(hex_string + i);
    hex_string_piece[1] = *(hex_string + (i + 1));
    *(out_bytes + outbyte_counter) = byte_from_hex_str(hex_string_piece);
    outbyte_counter++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bytes_from_hex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
je     1167 <bytes_from_hex_string+0x37>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <bytes_from_hex_string+0xc9>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f2 <bytes_from_hex_string+0xc2>
lea    -0x26(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x26(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x25(%rbp)
lea    -0x26(%rbp),%rdi
call   1030 <byte_from_hex_str@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <bytes_from_hex_string+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytes_from_hex_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    $0x1,%r15d
test   $0x1,%al
jne    118f <bytes_from_hex_string+0x6f>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    118c <bytes_from_hex_string+0x6c>
mov    %eax,%r13d
xor    %r15d,%r15d
lea    0x6(%rsp),%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%r14,%rbp,1),%eax
mov    %al,0x6(%rsp)
movzbl 0x1(%r14,%rbp,1),%eax
mov    %al,0x7(%rsp)
mov    %r12,%rdi
call   1030 <byte_from_hex_str@plt>
mov    %al,(%rbx)
add    $0x2,%rbp
add    $0x1,%rbx
cmp    %ebp,%r13d
jg     1160 <bytes_from_hex_string+0x40>
jmp    118f <bytes_from_hex_string+0x6f>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bytes_from_hex_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = srem i32 %11, 2
%13 = icmp ne i32 0, %12
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %49
15: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
store i32 0, i32* %6
br label %18
18: ; preds = %45, %15
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %48
22: ; preds = %18
%23 = bitcast [2 x i8]* %9 to i8*
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %28, i8* %29
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 %35, i8* %36
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%38 = call zeroext i8 @byte_from_hex_str(i8* %37)
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %45
45: ; preds = %22
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 2
store i32 %47, i32* %6
br label %18
48: ; preds = %18
store i32 0, i32* %3
br label %49
49: ; preds = %48, %14
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @bytes_from_hex_string(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to [2 x i8]*
%5 = tail call i32 @strlen(i8* %1)
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = bitcast i16* %3 to i8*
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %25, %14 ]
%16 = phi i64 [ 0, %11 ], [ %24, %14 ]
%17 = getelementptr inbounds i8, i8* %1, i64 %15
%18 = load i8, i8* %17
store i8 %18, i8* %12
%19 = or i64 %15, 1
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %13
%22 = call zeroext i8 @byte_from_hex_str(i8* %12)
%23 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %22, i8* %23
%24 = add nuw i64 %16, 1
%25 = add nuw i64 %15, 2
%26 = trunc i64 %25 to i32
%27 = icmp sgt i32 %9, %26
br i1 %27, label %14, label %28
28: ; preds = %14, %8, %2
%29 = phi i32 [ 1, %2 ], [ 0, %8 ], [ 0, %14 ]
ret i32 %29
}