#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*/ SHA1_HMAC(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *getCHMAC(char *dst, char *key, char *first, char *second) {
  if (key == NULL || strlen(key) < 1) {
    printf("[-] CHMAC could NOT be computed since the key was empty\n");
    exit(1);
  }
  char *ret = dst;
  strcpy(ret, "");
  if (second != NULL && strlen(second) > 0) {
    char text[strlen(first) + strlen(second) + 3];
    strcpy(text, first);
    strcat(text, " ");
    strcat(text, second);
    SHA1_HMAC(ret, key, text, 0);
  } else {
    SHA1_HMAC(ret, key, first, 0);
  }
  return ret;
}


x86 assembly (clang, -O0):
<getCHMAC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1195 <getCHMAC+0x35>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    11ab <getCHMAC+0x4b>
lea    0xe64(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     126a <getCHMAC+0x10a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    126a <getCHMAC+0x10a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x3(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %ecx,%ecx
call   1050 <SHA1_HMAC@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    127d <getCHMAC+0x11d>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <SHA1_HMAC@plt>
mov    -0x28(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCHMAC>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     123c <getCHMAC+0xdc>
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    123c <getCHMAC+0xdc>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
test   %r15,%r15
je     121a <getCHMAC+0xba>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    121a <getCHMAC+0xba>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rsp,-0x30(%rbp)
add    %ebx,%eax
add    $0x3,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <SHA1_HMAC@plt>
mov    -0x30(%rbp),%rsp
jmp    122a <getCHMAC+0xca>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1060 <SHA1_HMAC@plt>
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"[-] CHMAC could NOT be computed since the key was empty\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i8* @getCHMAC(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %14, %4
%19 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i8*, i8** %5
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %50
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %50
31: ; preds = %27
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
%34 = load i8*, i8** %8
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %33, %35
%37 = add nsw i32 %36, 3
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %10
%40 = alloca i8, i64 %38
store i64 %38, i64* %11
%41 = load i8*, i8** %7
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %8
%45 = call i32 @strcat(i8* %40, i8* %44)
%46 = load i8*, i8** %9
%47 = load i8*, i8** %6
%48 = call i32 @SHA1_HMAC(i8* %46, i8* %47, i8* %40, i32 0)
%49 = load i8*, i8** %10
br label %55
50: ; preds = %27, %21
%51 = load i8*, i8** %9
%52 = load i8*, i8** %6
%53 = load i8*, i8** %7
%54 = call i32 @SHA1_HMAC(i8* %51, i8* %52, i8* %53, i32 0)
br label %55
55: ; preds = %50, %31
%56 = load i8*, i8** %9
ret i8* %56
}

LLVM IR (-O2):
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
@str = [56 x i8] c"[-] CHMAC could NOT be computed since the key was empty\00"
define i8* @getCHMAC(i8* returned %0, i8* %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %6, %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %3, null
br i1 %14, label %30, label %15
15: ; preds = %12
%16 = tail call i32 @strlen(i8* %3)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %2)
%20 = tail call i32 @strlen(i8* %3)
%21 = add i32 %19, 3
%22 = add i32 %21, %20
%23 = zext i32 %22 to i64
%24 = tail call i8* @llvm.stacksave()
%25 = alloca i8, i64 %23
%26 = call i32 @strcpy(i8* %25, i8* %2)
%27 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @strcat(i8* %25, i8* %3)
%29 = call i32 @SHA1_HMAC(i8* %0, i8* %1, i8* %25, i32 0)
br label %32
30: ; preds = %15, %12
%31 = tail call i32 @SHA1_HMAC(i8* %0, i8* %1, i8* %2, i32 0)
br label %32
32: ; preds = %30, %18
ret i8* %0
}