#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*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
unsigned long zcrc64(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ztoupper(char *);
void zlicense_mac_build(char *salt, char *_mac, char *rbuf) {
  char mac[128];
  char buf[512];
  unsigned char *p;
  int i;
  unsigned long crc;
  strcpy(mac, _mac);
  ztoupper(mac);
  sprintf(buf, "%s,%s", salt, mac);
  crc = zcrc64(buf, strlen(buf), 0);
  p = (unsigned char *)(&crc);
  for (i = 0; i < 8; i++) {
    sprintf(rbuf + i * 2, "%02X", *p++);
  }
  rbuf[16] = 0;
}


x86 assembly (clang, -O0):
<zlicense_mac_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <ztoupper@plt>
lea    -0x2a0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2c0(%rbp)
lea    -0x2a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c0(%rbp),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <zcrc64@plt>
mov    %rax,-0x2b8(%rbp)
lea    -0x2b8(%rbp),%rax
mov    %rax,-0x2a8(%rbp)
movl   $0x0,-0x2ac(%rbp)
cmpl   $0x8,-0x2ac(%rbp)
jge    1247 <zlicense_mac_build+0xf7>
mov    -0x18(%rbp),%rdi
mov    -0x2ac(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x2a8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x2a8(%rbp)
movzbl (%rax),%eax
mov    %eax,%edx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x2ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2ac(%rbp)
jmp    11ec <zlicense_mac_build+0x9c>
mov    -0x18(%rbp),%rax
movb   $0x0,0x10(%rax)
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlicense_mac_build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2a8,%rsp
mov    %rdx,%rbx
mov    %rdi,%r14
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <ztoupper@plt>
lea    0xe7d(%rip),%rsi
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <zcrc64@plt>
movzbl %ah,%ecx
mov    %rcx,0x10(%rsp)
mov    %eax,%r12d
mov    %rax,%r13
mov    %rax,%r14
mov    %rax,%rbp
mov    %rax,%rcx
movzbl %al,%edx
shr    $0x10,%eax
movzbl %al,%eax
mov    %rax,0x8(%rsp)
shr    $0x18,%r12d
shr    $0x20,%r13
shr    $0x28,%r14
shr    $0x30,%rbp
shr    $0x38,%rcx
mov    %rcx,0x18(%rsp)
lea    0xe12(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x2(%rbx),%rdi
mov    %r15,%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x4(%rbx),%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x6(%rbx),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x8(%rbx),%rdi
movzbl %r13b,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xa(%rbx),%rdi
movzbl %r14b,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xc(%rbx),%rdi
movzbl %bpl,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe(%rbx),%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
movb   $0x0,0x10(%rbx)
add    $0x2a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s,%s\00"
@.str.1 = [5 x i8] c"%02X\00"
define void @zlicense_mac_build(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%16 = call i32 @ztoupper(i8* %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i64 @zcrc64(i8* %21, i32 %23, i32 0)
store i64 %24, i64* %11
%25 = bitcast i64* %11 to i8*
store i8* %25, i8** %9
store i32 0, i32* %10
br label %26
26: ; preds = %41, %3
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 8
br i1 %28, label %29, label %44
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = load i32, i32* %10
%32 = mul nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
%37 = load i8, i8* %35
%38 = zext i8 %37 to i64
%39 = inttoptr i64 %38 to i8*
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %29
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %26
44: ; preds = %26
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 16
store i8 0, i8* %46
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s,%s\00"
@.str.1 = [5 x i8] c"%02X\00"
define void @zlicense_mac_build(i8* %0, i8* %1, i8* nocapture writeonly %2) {
%4 = alloca [128 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = call i32 @strcpy(i8* %6, i8* %1)
%9 = call i32 @ztoupper(i8* %6)
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6)
%11 = call i32 @strlen(i8* %7)
%12 = call i64 @zcrc64(i8* %7, i32 %11, i32 0)
%13 = lshr i64 %12, 8
%14 = lshr i64 %12, 16
%15 = lshr i64 %12, 24
%16 = lshr i64 %12, 32
%17 = lshr i64 %12, 40
%18 = lshr i64 %12, 48
%19 = lshr i64 %12, 56
%20 = and i64 %12, 255
%21 = inttoptr i64 %20 to i8*
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds i8, i8* %2, i64 2
%24 = and i64 %13, 255
%25 = inttoptr i64 %24 to i8*
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds i8, i8* %2, i64 4
%28 = and i64 %14, 255
%29 = inttoptr i64 %28 to i8*
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds i8, i8* %2, i64 6
%32 = and i64 %15, 255
%33 = inttoptr i64 %32 to i8*
%34 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds i8, i8* %2, i64 8
%36 = and i64 %16, 255
%37 = inttoptr i64 %36 to i8*
%38 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds i8, i8* %2, i64 10
%40 = and i64 %17, 255
%41 = inttoptr i64 %40 to i8*
%42 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds i8, i8* %2, i64 12
%44 = and i64 %18, 255
%45 = inttoptr i64 %44 to i8*
%46 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds i8, i8* %2, i64 14
%48 = inttoptr i64 %19 to i8*
%49 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %47, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds i8, i8* %2, i64 16
store i8 0, i8* %50
ret void
}