#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__ isalnum(unsigned char);
size_t log_username(unsigned char *data, size_t length, char *buf,
                    size_t buflen) {
  size_t len = 0;
  size_t i;
  for (i = 5; i < length; i += 2) {
    if (isalnum(data[i]))
      buf[len++] = (char)data[i];
    else
      break;
  }
  buf[len] = '\0';
  return len;
}


x86 assembly (clang, -O0):
<log_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x5,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a2 <log_username+0x92>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     1187 <log_username+0x77>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    118c <log_username+0x7c>
jmp    11a2 <log_username+0x92>
jmp    1191 <log_username+0x81>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    1138 <log_username+0x28>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_username>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
cmp    $0x6,%rsi
jb     1157 <log_username+0x47>
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x5,%ebx
xor    %r13d,%r13d
movzbl (%r12,%rbx,1),%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     115a <log_username+0x4a>
movzbl (%r12,%rbx,1),%eax
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
add    $0x2,%rbx
cmp    %r15,%rbx
jb     1130 <log_username+0x20>
jmp    115a <log_username+0x4a>
xor    %r13d,%r13d
movb   $0x0,(%r14,%r13,1)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @log_username(i8* nocapture %0, i64 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = icmp ugt i64 %1, 5
br i1 %5, label %6, label %19
6: ; preds = %4, %13
%7 = phi i64 [ %17, %13 ], [ 5, %4 ]
%8 = phi i64 [ %15, %13 ], [ 0, %4 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @isalnum(i8 zeroext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = load i8, i8* %9
%15 = add i64 %8, 1
%16 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 %14, i8* %16
%17 = add i64 %7, 2
%18 = icmp ult i64 %17, %1
br i1 %18, label %6, label %19
19: ; preds = %13, %6, %4
%20 = phi i64 [ 0, %4 ], [ %8, %6 ], [ %15, %13 ]
%21 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 0, i8* %21
ret i64 %20
}