#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 ssize_t;

/* Variables and functions */
ssize_t challenge_transform(const char *username, unsigned char challenge[16],
                            size_t clen) {
  switch (16 - clen) {
  case 0:
    clen -= 2;
    break;
  case 1:
    clen -= 1;
    break;
  }
  if (*username)
    challenge[clen++] = *username++;
  if (*username)
    challenge[clen++] = *username++;
  return clen;
}


x86 assembly (clang, -O0):
<challenge_transform>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    $0x10,%eax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
je     113e <challenge_transform+0x3e>
jmp    112b <challenge_transform+0x2b>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
je     114f <challenge_transform+0x4f>
jmp    115b <challenge_transform+0x5b>
mov    -0x18(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    115b <challenge_transform+0x5b>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     118f <challenge_transform+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c3 <challenge_transform+0xc3>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<challenge_transform>:
mov    %rdx,%rax
mov    $0x10,%ecx
sub    %rdx,%rcx
cmp    $0x1,%rcx
je     111c <challenge_transform+0x1c>
test   %rcx,%rcx
jne    1120 <challenge_transform+0x20>
add    $0xfffffffffffffffe,%rax
jmp    1120 <challenge_transform+0x20>
add    $0xffffffffffffffff,%rax
mov    (%rdi),%cl
test   %cl,%cl
je     1138 <challenge_transform+0x38>
mov    %cl,(%rsi,%rax,1)
mov    0x1(%rdi),%cl
test   %cl,%cl
je     1139 <challenge_transform+0x39>
mov    %cl,0x1(%rsi,%rax,1)
add    $0x2,%rax
ret
add    $0x1,%rax
ret

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

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