#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 */
int strlen(char *);
int /*<<< orphan*/ syserr(char *);
int countTrailingBlanks(char *string, int position) {
  int skippedChars, i;
  skippedChars = 0;
  if (position > strlen(string) - 1)
    syserr("position > length in countTrailingBlanks");
  for (i = position; i >= 0 && string[i] == ' '; i--)
    skippedChars++;
  return (skippedChars);
}


x86 assembly (clang, -O0):
<countTrailingBlanks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1161 <countTrailingBlanks+0x41>
lea    0xea4(%rip),%rdi
call   1040 <syserr@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jl     118b <countTrailingBlanks+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119b <countTrailingBlanks+0x7b>
jmp    11b2 <countTrailingBlanks+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <countTrailingBlanks+0x47>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countTrailingBlanks>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    %ebx,%eax
jg     113e <countTrailingBlanks+0x1e>
lea    0xec7(%rip),%rdi
call   1040 <syserr@plt>
test   %ebx,%ebx
js     1165 <countTrailingBlanks+0x45>
lea    0x1(%rbx),%ecx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edx
cmpb   $0x20,(%r14,%rdx,1)
jne    1167 <countTrailingBlanks+0x47>
add    $0x1,%eax
add    $0xffffffff,%ebx
jb     1150 <countTrailingBlanks+0x30>
mov    %ecx,%eax
jmp    1167 <countTrailingBlanks+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"position > length in countTrailingBlanks\00"
define i32 @countTrailingBlanks(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = icmp sgt i32 %7, %10
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @syserr(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %4
store i32 %15, i32* %6
br label %16
16: ; preds = %32, %14
%17 = load i32, i32* %6
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 32
br label %27
27: ; preds = %19, %16
%28 = phi i1 [ false, %16 ], [ %26, %19 ]
br i1 %28, label %29, label %35
29: ; preds = %27
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %16
35: ; preds = %27
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str = [41 x i8] c"position > length in countTrailingBlanks\00"
define i32 @countTrailingBlanks(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, %1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @syserr(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = icmp sgt i32 %1, -1
br i1 %8, label %9, label %22
9: ; preds = %7
%10 = add nuw i32 %1, 1
br label %11
11: ; preds = %9, %18
%12 = phi i32 [ %20, %18 ], [ %1, %9 ]
%13 = phi i32 [ %19, %18 ], [ 0, %9 ]
%14 = zext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = add nuw i32 %13, 1
%20 = add nsw i32 %12, -1
%21 = icmp eq i32 %13, %1
br i1 %21, label %22, label %11
22: ; preds = %11, %18, %7
%23 = phi i32 [ 0, %7 ], [ %10, %18 ], [ %13, %11 ]
ret i32 %23
}