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

/* Variables and functions */
int *base64_decode(char *, int *);
char *base64_encode(int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *swaplanguage(char *session) {
  int out;
  uint8_t *raw;
  raw = base64_decode(session, &out);
  if ((raw == NULL) || (out != 20)) {
    fprintf(stderr, "invalid cookie");
    exit(1);
  }
  raw[12] = raw[12] ^ 0x03;
  return (base64_encode(raw, 20));
}


x86 assembly (clang, -O0):
<swaplanguage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <base64_decode@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1172 <swaplanguage+0x32>
cmpl   $0x14,-0xc(%rbp)
je     1191 <swaplanguage+0x51>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x30(%rax),%ecx
xor    $0x3,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x14,%esi
call   1040 <base64_encode@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swaplanguage>:
push   %rax
lea    0x4(%rsp),%rsi
call   1060 <base64_decode@plt>
test   %rax,%rax
je     116a <swaplanguage+0x2a>
cmpl   $0x14,0x4(%rsp)
jne    116a <swaplanguage+0x2a>
xorb   $0x3,0x30(%rax)
mov    %rax,%rdi
mov    $0x14,%esi
call   1040 <base64_encode@plt>
pop    %rcx
ret
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"invalid cookie\00"
define i8* @swaplanguage(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @base64_decode(i8* %5, i32* %3)
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 20
br i1 %11, label %12, label %16
12: ; preds = %9, %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 12
%19 = load i32, i32* %18
%20 = xor i32 %19, 3
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 12
store i32 %20, i32* %22
%23 = load i32*, i32** %4
%24 = call i8* @base64_encode(i32* %23, i32 20)
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"invalid cookie\00"
define i8* @swaplanguage(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32* @base64_decode(i8* %0, i32* %2)
%5 = icmp eq i32* %4, null
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 20
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = getelementptr inbounds i32, i32* %4, i64 12
%15 = load i32, i32* %14
%16 = xor i32 %15, 3
store i32 %16, i32* %14
%17 = call i8* @base64_encode(i32* %4, i32 20)
ret i8* %17
}