#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*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
unsigned long zcrc64(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ztoupper(char *);
void zlicense_mac_build(const char *salt, const char *_mac, char *rbuf) {
  char mac[128];
  char buf[512];
  unsigned char *p;
  int i;
  unsigned long crc;
  snprintf(mac, 127, "%s", _mac);
  ztoupper(mac);
  snprintf(buf, 511, "%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),%rcx
mov    $0x7f,%esi
lea    0xe85(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <ztoupper@plt>
lea    -0x2a0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    -0xa0(%rbp),%r8
mov    $0x1ff,%esi
lea    0xe51(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2c0(%rbp)
lea    -0x2a0(%rbp),%rdi
call   1030 <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    1256 <zlicense_mac_build+0x106>
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),%edx
lea    0xdc9(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x2ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2ac(%rbp)
jmp    11ff <zlicense_mac_build+0xaf>
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,%r12
mov    %rsi,%rcx
mov    %rdi,%r14
lea    0xe92(%rip),%rdx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x7f,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1050 <ztoupper@plt>
lea    0xe6c(%rip),%rdx
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <zcrc64@plt>
mov    %rax,%rbx
mov    %ebx,%r13d
shr    $0x10,%r13d
shr    $0x18,%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%r14
shr    $0x20,%r14
mov    %rbx,%rbp
shr    $0x28,%rbp
mov    %rbx,%rax
shr    $0x30,%rax
mov    %rax,0x10(%rsp)
mov    %rbx,%rax
shr    $0x38,%rax
mov    %rax,0x18(%rsp)
movzbl %bl,%edx
lea    0xe00(%rip),%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x2(%r12),%rdi
movzbl %bh,%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x4(%r12),%rdi
movzbl %r13b,%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0x6(%r12),%rdi
mov    %r15,%rsi
mov    0xc(%rsp),%edx
call   1070 <sprintf@plt>
lea    0x8(%r12),%rdi
movzbl %r14b,%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0xa(%r12),%rdi
movzbl %bpl,%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0xc(%r12),%rdi
movzbl 0x10(%rsp),%edx
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0xe(%r12),%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%rdx
call   1070 <sprintf@plt>
movb   $0x0,0x10(%r12)
add    $0x2a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%s,%s\00"
@.str.2 = [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 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %12, i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), 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*, i32, i8*, i8*, ...) @snprintf(i8* %17, i32 511, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, 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 = %40, %3
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 8
br i1 %28, label %29, label %43
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 i32
%39 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %29
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %26
43: ; preds = %26
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 16
store i8 0, i8* %45
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%s,%s\00"
@.str.2 = [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 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i32 @ztoupper(i8* %6)
%10 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 511, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, 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 = trunc i64 %12 to i32
%14 = trunc i64 %12 to i32
%15 = lshr i32 %14, 8
%16 = trunc i64 %12 to i32
%17 = lshr i32 %16, 16
%18 = trunc i64 %12 to i32
%19 = lshr i32 %18, 24
%20 = lshr i64 %12, 32
%21 = trunc i64 %20 to i32
%22 = lshr i64 %12, 40
%23 = trunc i64 %22 to i32
%24 = lshr i64 %12, 48
%25 = trunc i64 %24 to i32
%26 = lshr i64 %12, 56
%27 = trunc i64 %26 to i32
%28 = and i32 %13, 255
%29 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i8, i8* %2, i64 2
%31 = and i32 %15, 255
%32 = call i32 @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %2, i64 4
%34 = and i32 %17, 255
%35 = call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds i8, i8* %2, i64 6
%37 = call i32 @sprintf(i8* dereferenceable(1) %36, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%38 = getelementptr inbounds i8, i8* %2, i64 8
%39 = and i32 %21, 255
%40 = call i32 @sprintf(i8* dereferenceable(1) %38, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %2, i64 10
%42 = and i32 %23, 255
%43 = call i32 @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i8, i8* %2, i64 12
%45 = and i32 %25, 255
%46 = call i32 @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %2, i64 14
%48 = call i32 @sprintf(i8* dereferenceable(1) %47, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%49 = getelementptr inbounds i8, i8* %2, i64 16
store i8 0, i8* %49
ret void
}