#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 */
char *base64_encode(char *, int);
int /*<<< orphan*/ en3DES(char *, int, char const *, char const *, char const *,
                          char *, int *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
char *getSerialNumber(char *snnumber) {
  const char *key1 = "1234dcba";
  const char *key2 = "abcd4321";
  const char *key3 = "f8e75c6d";
  char outdata[64] = {0};
  char *base64en = NULL;
  int outlen = 0;
  if (strlen(snnumber) != 12) {
    printf("invalid SN code \n");
    return NULL;
  }
  en3DES(snnumber, strlen(snnumber), key1, key2, key3, outdata, &outlen);
  base64en = base64_encode(outdata, outlen);
  return base64en;
}


x86 assembly (clang, -O0):
<getSerialNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xc,%eax
je     11ca <getSerialNumber+0x7a>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    121c <getSerialNumber+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    -0x70(%rbp),%r9
lea    -0x7c(%rbp),%rax
mov    %rax,(%rsp)
call   1070 <en3DES@plt>
lea    -0x70(%rbp),%rdi
mov    -0x7c(%rbp),%esi
call   1060 <base64_encode@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSerialNumber>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
call   1040 <strlen@plt>
cmp    $0xc,%eax
jne    11b9 <getSerialNumber+0x79>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xc(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0xe75(%rip),%rdx
lea    0xe77(%rip),%rcx
lea    0xe79(%rip),%r8
lea    0x10(%rsp),%r14
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%r9
call   1060 <en3DES@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1050 <base64_encode@plt>
jmp    11c7 <getSerialNumber+0x87>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"1234dcba\00"
@.str.1 = [9 x i8] c"abcd4321\00"
@.str.2 = [9 x i8] c"f8e75c6d\00"
@.str.3 = [18 x i8] c"invalid SN code \0A\00"
define i8* @getSerialNumber(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [64 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %6
%10 = bitcast [64 x i8]* %7 to i8*
store i8* null, i8** %8
store i32 0, i32* %9
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %29
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = call i32 @en3DES(i8* %17, i32 %19, i8* %20, i8* %21, i8* %22, i8* %23, i32* %9)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* %9
%27 = call i8* @base64_encode(i8* %25, i32 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
store i8* %28, i8** %2
br label %29
29: ; preds = %16, %14
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [9 x i8] c"1234dcba\00"
@.str.1 = [9 x i8] c"abcd4321\00"
@.str.2 = [9 x i8] c"f8e75c6d\00"
@str = [17 x i8] c"invalid SN code \00"
define i8* @getSerialNumber(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 12
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %15
10: ; preds = %1
%11 = tail call i32 @strlen(i8* %0)
%12 = call i32 @en3DES(i8* %0, i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32* %3)
%13 = load i32, i32* %3
%14 = call i8* @base64_encode(i8* %4, i32 %13)
br label %15
15: ; preds = %10, %8
%16 = phi i8* [ null, %8 ], [ %14, %10 ]
ret i8* %16
}