#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*/ printf(char *);
int sam3Base32Encode(char *, char const *, int);
int sam3Base32EncodedLength(int);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
void testb32(const char *src, const char *res) {
  int dlen = sam3Base32EncodedLength(strlen(src)), len;
  char dest[128];
  len = sam3Base32Encode(dest, src, strlen(src));
  printf("test ");
  if (len != dlen || len != strlen(res) || strcmp(res, dest) != 0) {
    printf("FAILED!\n");
  } else {
    printf("passed\n");
  }
}


x86 assembly (clang, -O0):
<testb32>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1070 <sam3Base32EncodedLength@plt>
mov    %eax,-0x14(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1060 <sam3Base32Encode@plt>
mov    %eax,-0x18(%rbp)
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1204 <testb32+0xb4>
mov    -0x18(%rbp),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
cmp    %ecx,%eax
jne    1204 <testb32+0xb4>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1215 <testb32+0xc5>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
jmp    1221 <testb32+0xd1>
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testb32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <sam3Base32EncodedLength@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <sam3Base32Encode@plt>
mov    %eax,%ebp
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    0xe61(%rip),%rbx
cmp    %r15d,%ebp
jne    11de <testb32+0x7e>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r15d
jne    11de <testb32+0x7e>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe33(%rip),%rax
lea    0xe33(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test \00"
@.str.1 = [9 x i8] c"FAILED!\0A\00"
@.str.2 = [8 x i8] c"passed\0A\00"
define void @testb32(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @sam3Base32EncodedLength(i32 %9)
store i32 %10, i32* %5
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @sam3Base32Encode(i8* %11, i8* %12, i32 %14)
store i32 %15, i32* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = icmp ne i32 %17, %18
br i1 %19, label %30, label %20
20: ; preds = %2
%21 = load i32, i32* %6
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = icmp ne i32 %21, %23
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25, %20, %2
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"test \00"
@str = [7 x i8] c"passed\00"
@str.3 = [8 x i8] c"FAILED!\00"
define void @testb32(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @sam3Base32EncodedLength(i32 %4)
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %0)
%8 = call i32 @sam3Base32Encode(i8* %6, i8* %0, i32 %7)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %8, %5
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = call i32 @strlen(i8* %1)
%13 = icmp eq i32 %5, %12
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i64 @strcmp(i8* %1, i8* %6)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.3, i64 0, i64 0)
br label %18
18: ; preds = %14, %2, %11
%19 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.3, i64 0, i64 0), %2 ], [ %17, %14 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
ret void
}