#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 /*<<< orphan*/ BUFSIZ;
scalar_t__ pencil_degradation(char);
size_t strnlen(char const *, int /*<<< orphan*/);
unsigned int pencil_str_degradation(const char *text) {
  unsigned int degradation = 0;
  size_t text_length = strnlen(text, BUFSIZ);
  char character;
  for (size_t pos = 0; pos < text_length; ++pos) {
    character = text[pos];
    degradation += pencil_degradation(character);
  }
  return degradation;
}


x86 assembly (clang, -O0):
<pencil_str_degradation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
call   1030 <strnlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1193 <pencil_str_degradation+0x73>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1040 <pencil_degradation@plt>
mov    %rax,%rcx
mov    -0xc(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1151 <pencil_str_degradation+0x31>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pencil_str_degradation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
call   1030 <strnlen@plt>
test   %rax,%rax
je     1167 <pencil_str_degradation+0x47>
mov    %rax,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r14,%rbx,1),%edi
call   1040 <pencil_degradation@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <pencil_str_degradation+0x30>
jmp    1169 <pencil_str_degradation+0x49>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i32 @pencil_str_degradation(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8
%6 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = load i8*, i8** %2
%8 = load i32, i32* @BUFSIZ
%9 = call i64 @strnlen(i8* %7, i32 %8)
store i64 %9, i64* %4
store i64 0, i64* %6
br label %10
10: ; preds = %25, %1
%11 = load i64, i64* %6
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i64, i64* %6
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %5
%19 = load i8, i8* %5
%20 = call i64 @pencil_degradation(i8 signext %19)
%21 = load i32, i32* %3
%22 = zext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %3
br label %25
25: ; preds = %14
%26 = load i64, i64* %6
%27 = add i64 %26, 1
store i64 %27, i64* %6
br label %10
28: ; preds = %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define i32 @pencil_str_degradation(i8* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = tail call i64 @strnlen(i8* %0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %7, %1
%6 = phi i32 [ 0, %1 ], [ %14, %7 ]
ret i32 %6
7: ; preds = %1, %7
%8 = phi i64 [ %15, %7 ], [ 0, %1 ]
%9 = phi i32 [ %14, %7 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = tail call i64 @pencil_degradation(i8 signext %11)
%13 = trunc i64 %12 to i32
%14 = add i32 %9, %13
%15 = add nuw i64 %8, 1
%16 = icmp eq i64 %15, %3
br i1 %16, label %5, label %7
}