#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 */
struct gdb_data {
  int dummy;
};

/* Variables and functions */
int gdb_flush_ack(struct gdb_data *);
int /*<<< orphan*/ gdb_packet_end(struct gdb_data *);
int /*<<< orphan*/ gdb_packet_start(struct gdb_data *);
int /*<<< orphan*/ gdb_printf(struct gdb_data *, char *, int /*<<< orphan*/);
int gdb_send_hex(struct gdb_data *data, const char *text) {
  gdb_packet_start(data);
  while (*text)
    gdb_printf(data, "%02x", *(text++));
  gdb_packet_end(data);
  return gdb_flush_ack(data);
}


x86 assembly (clang, -O0):
<gdb_send_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gdb_packet_start@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     118d <gdb_send_hex+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edx
lea    0xe7d(%rip),%rsi
call   1050 <gdb_printf@plt>
jmp    1159 <gdb_send_hex+0x19>
mov    -0x8(%rbp),%rdi
call   1060 <gdb_packet_end@plt>
mov    -0x8(%rbp),%rdi
call   1040 <gdb_flush_ack@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_send_hex>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <gdb_packet_start@plt>
mov    (%rbx),%al
test   %al,%al
je     1189 <gdb_send_hex+0x49>
add    $0x1,%rbx
lea    0xe9f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <gdb_printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <gdb_send_hex+0x30>
mov    %r14,%rdi
call   1060 <gdb_packet_end@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <gdb_flush_ack@plt>

LLVM IR (-O0):
%struct.gdb_data = type { i32 }
@.str = [5 x i8] c"%02x\00"
define i32 @gdb_send_hex(%struct.gdb_data* %0, i8* %1) {
%3 = alloca %struct.gdb_data*
%4 = alloca i8*
store %struct.gdb_data* %0, %struct.gdb_data** %3
store i8* %1, i8** %4
%5 = load %struct.gdb_data*, %struct.gdb_data** %3
%6 = call i32 @gdb_packet_start(%struct.gdb_data* %5)
br label %7
7: ; preds = %11, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load %struct.gdb_data*, %struct.gdb_data** %3
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = call i32 @gdb_printf(%struct.gdb_data* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %7
18: ; preds = %7
%19 = load %struct.gdb_data*, %struct.gdb_data** %3
%20 = call i32 @gdb_packet_end(%struct.gdb_data* %19)
%21 = load %struct.gdb_data*, %struct.gdb_data** %3
%22 = call i32 @gdb_flush_ack(%struct.gdb_data* %21)
ret i32 %22
}

LLVM IR (-O2):
%struct.gdb_data = type { i32 }
@.str = [5 x i8] c"%02x\00"
define i32 @gdb_send_hex(%struct.gdb_data* %0, i8* nocapture %1) {
%3 = tail call i32 @gdb_packet_start(%struct.gdb_data* %0)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2, %6
%7 = phi i8 [ %12, %6 ], [ %4, %2 ]
%8 = phi i8* [ %9, %6 ], [ %1, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = sext i8 %7 to i32
%11 = tail call i32 @gdb_printf(%struct.gdb_data* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %2
%15 = tail call i32 @gdb_packet_end(%struct.gdb_data* %0)
%16 = tail call i32 @gdb_flush_ack(%struct.gdb_data* %0)
ret i32 %16
}