#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 */
scalar_t__ isspace(char);
char *find_end_of_text(char *string) {
  char *end = string;
  while (*string != '\0') {
    if (!isspace(*string)) {
      end = string;
    }
    string++;
  }
  if (*end == '\0') {
    return end;
  }
  if (isspace(*end)) {
    return end;
  }
  return end + 1;
}


x86 assembly (clang, -O0):
<find_end_of_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1163 <find_end_of_text+0x53>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
jne    1152 <find_end_of_text+0x42>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <find_end_of_text+0x14>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <find_end_of_text+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <find_end_of_text+0x9f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11a3 <find_end_of_text+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <find_end_of_text+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_end_of_text>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     1152 <find_end_of_text+0x42>
mov    %r14,%rbx
movsbl %al,%edi
call   1030 <isspace@plt>
test   %rax,%rax
cmove  %rbx,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1120 <find_end_of_text+0x10>
mov    (%r14),%al
test   %al,%al
je     1152 <find_end_of_text+0x42>
movsbl %al,%edi
call   1030 <isspace@plt>
cmp    $0x1,%rax
adc    $0x0,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @find_end_of_text(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
br label %6
6: ; preds = %18, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = call i64 @isspace(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = load i8*, i8** %3
store i8* %17, i8** %4
br label %18
18: ; preds = %16, %11
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %6
21: ; preds = %6
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i8*, i8** %4
store i8* %27, i8** %2
br label %38
28: ; preds = %21
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = call i64 @isspace(i8 signext %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i8*, i8** %4
store i8* %34, i8** %2
br label %38
35: ; preds = %28
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %2
br label %38
38: ; preds = %35, %33, %26
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
define i8* @find_end_of_text(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %12, %4 ], [ %2, %1 ]
%6 = phi i8* [ %10, %4 ], [ %0, %1 ]
%7 = phi i8* [ %11, %4 ], [ %0, %1 ]
%8 = tail call i64 @isspace(i8 signext %5)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* %7, i8* %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = load i8, i8* %10
%16 = icmp eq i8 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = tail call i64 @isspace(i8 signext %15)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i64
%21 = getelementptr i8, i8* %10, i64 %20
br label %22
22: ; preds = %1, %17, %14
%23 = phi i8* [ %10, %14 ], [ %21, %17 ], [ %0, %1 ]
ret i8* %23
}