#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*/ sscanf(char *, char *, int *);
char *str_sub(char const *, int, int);
int strlen(char const *);
void stringToBytes(const char *string, unsigned char *bytes) {
  int i, j, tmp, t_string;
  char *byte;
  t_string = strlen(string);
  for (i = 0, j = 0; i < t_string - 1; i = i + 2, j++) {
    byte = str_sub(string, i, i + 1);
    sscanf(byte, "%x", &tmp);
    bytes[j] = tmp;
  }
}


x86 assembly (clang, -O0):
<stringToBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11bc <stringToBytes+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1050 <str_sub@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe74(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115a <stringToBytes+0x2a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringToBytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     118e <stringToBytes+0x5e>
mov    %eax,%r15d
add    $0xffffffff,%r15d
xor    %ebp,%ebp
lea    0xea5(%rip),%r12
lea    0x4(%rsp),%r13
lea    0x1(%rbp),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <str_sub@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x2,%ebp
cmp    %r15d,%ebp
jl     1160 <stringToBytes+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define void @stringToBytes(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %8
store i32 0, i32* %5
store i32 0, i32* %6
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %8
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = call i8* @str_sub(i8* %18, i32 %19, i32 %21)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%25 = load i32, i32* %7
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %17
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 2
store i32 %33, i32* %5
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %12
36: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @stringToBytes(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = icmp sgt i32 %5, 1
br i1 %7, label %8, label %20
8: ; preds = %2, %8
%9 = phi i64 [ %18, %8 ], [ 0, %2 ]
%10 = phi i32 [ %17, %8 ], [ 0, %2 ]
%11 = or i32 %10, 1
%12 = call i8* @str_sub(i8* %0, i32 %10, i32 %11)
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %15, i8* %16
%17 = add nuw nsw i32 %10, 2
%18 = add nuw i64 %9, 1
%19 = icmp slt i32 %17, %6
br i1 %19, label %8, label %20
20: ; preds = %8, %2
ret void
}