#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 gdbserv {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gdbserv_output_byte(struct gdbserv *, char const);
int strlen(char const *);
void gdbserv_output_string_as_bytes(struct gdbserv *gdbserv,
                                    const char *packet) {
  int i;
  int len = strlen(packet);
  for (i = 0; i < len; i++) {
    gdbserv_output_byte(gdbserv, packet[i]);
  }
}


x86 assembly (clang, -O0):
<gdbserv_output_string_as_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1172 <gdbserv_output_string_as_bytes+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <gdbserv_output_byte@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <gdbserv_output_string_as_bytes+0x23>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbserv_output_string_as_bytes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1156 <gdbserv_output_string_as_bytes+0x36>
mov    %eax,%r12d
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <gdbserv_output_byte@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <gdbserv_output_string_as_bytes+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.gdbserv = type { i32 }
define void @gdbserv_output_string_as_bytes(%struct.gdbserv* %0, i8* %1) {
%3 = alloca %struct.gdbserv*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store %struct.gdbserv* %0, %struct.gdbserv** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load %struct.gdbserv*, %struct.gdbserv** %3
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @gdbserv_output_byte(%struct.gdbserv* %14, i8 signext %19)
br label %21
21: ; preds = %13
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %9
24: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.gdbserv = type { i32 }
define void @gdbserv_output_string_as_bytes(%struct.gdbserv* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = tail call i32 @gdbserv_output_byte(%struct.gdbserv* %0, i8 signext %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %2
ret void
}