#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 int /*<<< orphan*/ plaintext;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int);
int lws_b64_decode_string(char const *const, char *, int);
int lws_b64_encode_string(char const *const, int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char const *const);
int strlen(char const *const);
int lws_b64_selftest(void) {
  char buf[64];
  int n;
  int test;
  static const char *const plaintext[] = {"sanity check base 64"};
  static const char *const coded[] = {"c2FuaXR5IGNoZWNrIGJhc2UgNjQ="};
  for (test = 0; test < sizeof plaintext / sizeof(plaintext[0]); test++) {
    buf[sizeof(buf) - 1] = '\0';
    n = lws_b64_encode_string(plaintext[test], strlen(plaintext[test]), buf,
                              sizeof buf);
    if (n != strlen(coded[test]) || strcmp(buf, coded[test])) {
      fprintf(stderr,
              "Failed lws_b64 encode selftest "
              "%d result '%s' %d\n",
              test, buf, n);
      return -1;
    }
    buf[sizeof(buf) - 1] = '\0';
    n = lws_b64_decode_string(coded[test], buf, sizeof buf);
    if (n != strlen(plaintext[test]) || strcmp(buf, plaintext[test])) {
      fprintf(stderr,
              "Failed lws_b64 decode selftest "
              "%d result '%s' %d\n",
              test, buf, n);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<lws_b64_selftest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x58(%rbp)
movslq -0x58(%rbp),%rax
cmp    $0x1,%rax
jae    12d0 <lws_b64_selftest+0x180>
movb   $0x0,-0x11(%rbp)
movslq -0x58(%rbp),%rcx
lea    0x2c8c(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x68(%rbp)
movslq -0x58(%rbp),%rcx
lea    0x2c79(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
mov    $0x40,%ecx
call   1030 <lws_b64_encode_string@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movslq -0x58(%rbp),%rcx
lea    0x2c50(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jne    11f8 <lws_b64_selftest+0xa8>
lea    -0x50(%rbp),%rdi
movslq -0x58(%rbp),%rcx
lea    0x2c2b(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1224 <lws_b64_selftest+0xd4>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
lea    -0x50(%rbp),%rcx
mov    -0x54(%rbp),%r8d
lea    0xe1f(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d7 <lws_b64_selftest+0x187>
movb   $0x0,-0x11(%rbp)
movslq -0x58(%rbp),%rcx
lea    0x2bdd(%rip),%rax
mov    (%rax,%rcx,8),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1040 <lws_b64_decode_string@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movslq -0x58(%rbp),%rcx
lea    0x2baf(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jne    1291 <lws_b64_selftest+0x141>
lea    -0x50(%rbp),%rdi
movslq -0x58(%rbp),%rcx
lea    0x2b8a(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12bd <lws_b64_selftest+0x16d>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
lea    -0x50(%rbp),%rcx
mov    -0x54(%rbp),%r8d
lea    0xdb8(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d7 <lws_b64_selftest+0x187>
jmp    12c2 <lws_b64_selftest+0x172>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    115f <lws_b64_selftest+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lws_b64_selftest>:
push   %rbx
sub    $0x40,%rsp
movb   $0x0,0x3f(%rsp)
lea    0xe9f(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x40,%ecx
call   1030 <lws_b64_encode_string@plt>
mov    %eax,%ebx
lea    0xe91(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
jne    11a1 <lws_b64_selftest+0x51>
lea    0xe81(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c9 <lws_b64_selftest+0x79>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %rsp,%rcx
xor    %edx,%edx
mov    %ebx,%r8d
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbx
ret
movb   $0x0,0x3f(%rsp)
lea    0xe40(%rip),%rdi
mov    %rsp,%rsi
mov    $0x40,%edx
call   1040 <lws_b64_decode_string@plt>
mov    %eax,%ebx
lea    0xe15(%rip),%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
jne    1208 <lws_b64_selftest+0xb8>
lea    0xe05(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     121a <lws_b64_selftest+0xca>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
jmp    11b1 <lws_b64_selftest+0x61>
xor    %eax,%eax
jmp    11c3 <lws_b64_selftest+0x73>

LLVM IR (-O0):
@lws_b64_selftest.plaintext = internal constant [1 x i8*] [i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i32 0, i32 0)]
@.str = [21 x i8] c"sanity check base 64\00"
@lws_b64_selftest.coded = internal constant [1 x i8*] [i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i32 0, i32 0)]
@.str.1 = [29 x i8] c"c2FuaXR5IGNoZWNrIGJhc2UgNjQ=\00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"Failed lws_b64 encode selftest %d result '%s' %d\0A\00"
@.str.3 = [50 x i8] c"Failed lws_b64 decode selftest %d result '%s' %d\0A\00"
define i32 @lws_b64_selftest() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %4
br label %5
5: ; preds = %73, %0
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 1
br i1 %8, label %9, label %76
9: ; preds = %5
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 63
store i8 0, i8* %10
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.plaintext, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.plaintext, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%21 = call i32 @lws_b64_encode_string(i8* %14, i32 %19, i8* %20, i32 64)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.coded, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = icmp ne i32 %22, %27
br i1 %28, label %37, label %29
29: ; preds = %9
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.coded, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %30, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %29, %9
%38 = load i32, i32* @stderr
%39 = load i32, i32* %4
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%41 = load i32, i32* %3
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %39, i8* %40, i32 %41)
store i32 -1, i32* %1
br label %77
43: ; preds = %29
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 63
store i8 0, i8* %44
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.coded, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%50 = call i32 @lws_b64_decode_string(i8* %48, i8* %49, i32 64)
store i32 %50, i32* %3
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.plaintext, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @strlen(i8* %55)
%57 = icmp ne i32 %51, %56
br i1 %57, label %66, label %58
58: ; preds = %43
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%60 = load i32, i32* %4
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1 x i8*], [1 x i8*]* @lws_b64_selftest.plaintext, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = call i64 @strcmp(i8* %59, i8* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %58, %43
%67 = load i32, i32* @stderr
%68 = load i32, i32* %4
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%70 = load i32, i32* %3
%71 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %68, i8* %69, i32 %70)
store i32 -1, i32* %1
br label %77
72: ; preds = %58
br label %73
73: ; preds = %72
%74 = load i32, i32* %4
%75 = add nsw i32 %74, 1
store i32 %75, i32* %4
br label %5
76: ; preds = %5
store i32 0, i32* %1
br label %77
77: ; preds = %76, %66, %37
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
@.str = [21 x i8] c"sanity check base 64\00"
@.str.1 = [29 x i8] c"c2FuaXR5IGNoZWNrIGJhc2UgNjQ=\00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"Failed lws_b64 encode selftest %d result '%s' %d\0A\00"
@.str.3 = [50 x i8] c"Failed lws_b64 decode selftest %d result '%s' %d\0A\00"
define i32 @lws_b64_selftest() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 63
store i8 0, i8* %3
%4 = call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @lws_b64_encode_string(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %2, i32 64)
%6 = call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8, %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* %2, i32 %5)
br label %24
14: ; preds = %8
store i8 0, i8* %3
%15 = call i32 @lws_b64_decode_string(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 64)
%16 = call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %14
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* %2, i32 %15)
br label %24
24: ; preds = %18, %21, %11
%25 = phi i32 [ -1, %11 ], [ -1, %21 ], [ 0, %18 ]
ret i32 %25
}