#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 */
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char);
uint16_t check_pkt_data_len(char *data) {
  data += 500;
  uint16_t i;
  for (i = 500 - 1; i >= 0; i--) {
    if (data[i] != ' ') {
      break;
    }
    printf("%c ", data[i]);
  }
  return i;
}


x86 assembly (clang, -O0):
<check_pkt_data_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1f4,%rax
mov    %rax,-0x8(%rbp)
movq   $0x1f3,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jb     1180 <check_pkt_data_len+0x70>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1157 <check_pkt_data_len+0x47>
jmp    1180 <check_pkt_data_len+0x70>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
lea    0xe9a(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <check_pkt_data_len+0x22>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pkt_data_len>:
push   %r15
push   %r14
push   %rbx
mov    $0x1f3,%eax
cmpb   $0x20,0x3e7(%rdi)
jne    115f <check_pkt_data_len+0x4f>
mov    %rdi,%r15
mov    $0x1f3,%ebx
lea    0xece(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <printf@plt>
lea    -0x1(%rbx),%rax
cmpb   $0x20,0x1f3(%r15,%rbx,1)
mov    %rax,%rbx
je     1140 <check_pkt_data_len+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%c \00"
define i64 @check_pkt_data_len(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 500
store i8* %5, i8** %2
store i64 499, i64* %3
br label %6
6: ; preds = %23, %1
%7 = load i64, i64* %3
%8 = icmp uge i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i64, i64* %3
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 32
br i1 %15, label %16, label %17
16: ; preds = %9
br label %26
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i64, i64* %3
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %21)
br label %23
23: ; preds = %17
%24 = load i64, i64* %3
%25 = add i64 %24, -1
store i64 %25, i64* %3
br label %6
26: ; preds = %16, %6
%27 = load i64, i64* %3
ret i64 %27
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c \00"
define i64 @check_pkt_data_len(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 500
%3 = getelementptr inbounds i8, i8* %0, i64 999
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 32
br i1 %5, label %6, label %13
6: ; preds = %1, %6
%7 = phi i64 [ %9, %6 ], [ 499, %1 ]
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext 32)
%9 = add i64 %7, -1
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 32
br i1 %12, label %6, label %13
13: ; preds = %6, %1
%14 = phi i64 [ 499, %1 ], [ %9, %6 ]
ret i64 %14
}