#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_char(struct gdbserv *, char const);
int strlen(char const *);
void gdbserv_output_string(struct gdbserv *gdbserv, const char *packet) {
  int i;
  for (i = 0; i < strlen(packet); i++)
    gdbserv_output_char(gdbserv, packet[i]);
}


x86 assembly (clang, -O0):
<gdbserv_output_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1176 <gdbserv_output_string+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <gdbserv_output_char@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <gdbserv_output_string+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbserv_output_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1160 <gdbserv_output_string+0x40>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <gdbserv_output_char@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <gdbserv_output_string+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.gdbserv = type { i32 }
define void @gdbserv_output_string(%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, %5
%6 = phi i64 [ %10, %5 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = tail call i32 @gdbserv_output_char(%struct.gdbserv* %0, i8 signext %8)
%10 = add nuw nsw i64 %6, 1
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %10, %12
br i1 %13, label %5, label %14
14: ; preds = %5, %2
ret void
}