#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*/ sprintf(char *, char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ xtoi(int /*<<< orphan*/, int *);
int convert_raw(char frame[32], char raw[64]) {
  int i, ascii;
  char byte[1], hex_byte[1];
  sprintf(raw, "%s", "");
  sprintf(frame, "%s", frame);
  for (i = 0; i < strlen(frame); i = i + 2) {
    strncpy(byte, frame + i, 2);
    byte[2] = '\0';
    sprintf(hex_byte, "%X", byte[0, 1]);
    xtoi(strncpy(byte, frame + i, 2), &ascii);
    sprintf(hex_byte, "%c", ascii);
    raw[i / 2] = hex_byte[0];
  }
  return i / 2;
}


x86 assembly (clang, -O0):
<convert_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
lea    0xea3(%rip),%rdx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1244 <convert_raw+0x104>
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x17(%rbp)
lea    -0x1a(%rbp),%rdi
movsbl -0x18(%rbp),%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <xtoi@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x1a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <convert_raw+0x46>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_raw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
movb   $0x0,(%rsi)
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e0 <convert_raw+0xa0>
lea    0x2(%rsp),%r12
lea    0x4(%rsp),%r13
xor    %ebx,%ebx
nopl   (%rax)
lea    (%r14,%rbx,1),%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rsp)
movsbl 0x3(%rsp),%edx
lea    0x3(%rsp),%rdi
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %eax,%edi
mov    %r13,%rsi
call   1050 <xtoi@plt>
movzbl 0x4(%rsp),%eax
movb   $0x0,0x4(%rsp)
mov    %al,(%r15)
add    $0x2,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x1,%r15
cmp    %ebx,%eax
jg     1170 <convert_raw+0x30>
shr    %ebx
jmp    11e2 <convert_raw+0xa2>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"%X\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @convert_raw(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x i8]
%8 = alloca [1 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %5
br label %14
14: ; preds = %49, %2
%15 = load i32, i32* %5
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %52
19: ; preds = %14
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @strncpy(i8* %20, i8* %24, i32 2)
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 2
store i8 0, i8* %26
%27 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%28 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = call i32 @strncpy(i8* %32, i8* %36, i32 2)
%38 = call i32 @xtoi(i32 %37, i32* %6)
%39 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%40 = load i32, i32* %6
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%43 = load i8, i8* %42
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = sdiv i32 %45, 2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 %43, i8* %48
br label %49
49: ; preds = %19
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 2
store i32 %51, i32* %5
br label %14
52: ; preds = %14
%53 = load i32, i32* %5
%54 = sdiv i32 %53, 2
ret i32 %54
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%X\00"
define i32 @convert_raw(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [1 x i8]
%5 = alloca [1 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
store i8 0, i8* %1
%9 = call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %2
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 2
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 1
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 1
br label %15
15: ; preds = %11, %15
%16 = phi i64 [ 0, %11 ], [ %28, %15 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = call i32 @strncpy(i8* %7, i8* %17, i32 2)
store i8 0, i8* %12
%19 = load i8, i8* %13
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @strncpy(i8* %7, i8* %17, i32 2)
%23 = call i32 @xtoi(i32 %22, i32* %3)
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
store i8 0, i8* %14
%26 = lshr exact i64 %16, 1
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 %25, i8* %27
%28 = add nuw i64 %16, 2
%29 = call i32 @strlen(i8* %0)
%30 = trunc i64 %28 to i32
%31 = icmp sgt i32 %29, %30
br i1 %31, label %15, label %32
32: ; preds = %15
%33 = trunc i64 %28 to i32
%34 = lshr exact i32 %33, 1
br label %35
35: ; preds = %32, %2
%36 = phi i32 [ 0, %2 ], [ %34, %32 ]
ret i32 %36
}