#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 const *, char *, unsigned int *);
int ihex_get_data(const char *input_string, unsigned char *data,
                  size_t data_size) {
  int error = 0;
  size_t i;
  unsigned int temp_data;
  for (i = 0; i < data_size; i++) {
    if (!sscanf(&(input_string[9 + i * 2]), "%02x", &temp_data)) {
      error = 1;
    } else {
      data[i] = (unsigned char)temp_data;
    }
  }
  return error;
}


x86 assembly (clang, -O0):
<ihex_get_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119f <ihex_get_data+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
add    $0x9,%rax
add    %rax,%rdi
lea    0xea5(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x0,%eax
jne    1179 <ihex_get_data+0x69>
movl   $0x1,-0x1c(%rbp)
jmp    1189 <ihex_get_data+0x79>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    118e <ihex_get_data+0x7e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1133 <ihex_get_data+0x23>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_get_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1181 <ihex_get_data+0x71>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x9,%rbx
xor    %r13d,%r13d
lea    0xec9(%rip),%r12
lea    0x4(%rsp),%rbp
movl   $0x0,(%rsp)
jmp    1166 <ihex_get_data+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x4(%rsp),%eax
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
add    $0x2,%rbx
cmp    %r13,%r15
je     1188 <ihex_get_data+0x78>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1030 <sscanf@plt>
test   %eax,%eax
jne    1150 <ihex_get_data+0x40>
movl   $0x1,(%rsp)
jmp    1159 <ihex_get_data+0x49>
movl   $0x0,(%rsp)
mov    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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