#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 /*<<< orphan*/ uuid;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
scalar_t__ get_uuid_by_docker_cpuset(char *, int);
scalar_t__ get_uuid_by_partition(char *, int);
int /*<<< orphan*/ revstr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sha1sum(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *lic_getmid() {
  fclose(stderr);
  char uuid[128] = "";
  if (get_uuid_by_partition(uuid, sizeof(uuid)) != 0) {
    if (get_uuid_by_docker_cpuset(uuid, sizeof(uuid)) != 0) {
      return NULL;
    }
  }
  revstr(uuid, strlen(uuid));
  char sum[40];
  sha1sum(uuid, strlen(uuid), sum);
  char *mid = calloc(47, 1);
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 5; j++) {
      mid[i * 5 + i + j] = sum[i * 5 + j];
    }
    mid[i * 5 + i - 1] = '-';
  }
  return mid;
}


x86 assembly (clang, -O0):
<lic_getmid>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1060 <fclose@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   10a0 <get_uuid_by_partition@plt>
cmp    $0x0,%rax
je     11f4 <lic_getmid+0x74>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1050 <get_uuid_by_docker_cpuset@plt>
cmp    $0x0,%rax
je     11ef <lic_getmid+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    1316 <lic_getmid+0x196>
jmp    11f4 <lic_getmid+0x74>
lea    -0x90(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x90(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    %eax,%esi
call   1030 <revstr@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x90(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%esi
lea    -0xc0(%rbp),%rdx
call   1040 <sha1sum@plt>
mov    $0x2f,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0xc8(%rbp)
movl   $0x0,-0xcc(%rbp)
cmpl   $0x8,-0xcc(%rbp)
jge    130b <lic_getmid+0x18b>
movl   $0x0,-0xd0(%rbp)
cmpl   $0x5,-0xd0(%rbp)
jge    12d9 <lic_getmid+0x159>
imul   $0x5,-0xcc(%rbp),%eax
add    -0xd0(%rbp),%eax
cltq
mov    -0xc0(%rbp,%rax,1),%dl
mov    -0xc8(%rbp),%rax
imul   $0x5,-0xcc(%rbp),%ecx
add    -0xcc(%rbp),%ecx
add    -0xd0(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xd0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd0(%rbp)
jmp    1282 <lic_getmid+0x102>
mov    -0xc8(%rbp),%rax
imul   $0x5,-0xcc(%rbp),%ecx
add    -0xcc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0xcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
jmp    126b <lic_getmid+0xeb>
mov    -0xc8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lic_getmid>:
push   %rbx
sub    $0xb0,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1060 <fclose@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
mov    $0x80,%esi
call   1090 <get_uuid_by_partition@plt>
test   %rax,%rax
je     11e9 <lic_getmid+0x79>
lea    0x30(%rsp),%rdi
mov    $0x80,%esi
call   1050 <get_uuid_by_docker_cpuset@plt>
test   %rax,%rax
je     11e9 <lic_getmid+0x79>
xor    %eax,%eax
jmp    12b2 <lic_getmid+0x142>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <revstr@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <sha1sum@plt>
mov    $0x2f,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    0x4(%rsp),%cl
mov    %cl,0x4(%rax)
mov    (%rsp),%ecx
mov    %ecx,(%rax)
movb   $0x2d,-0x1(%rax)
mov    0x5(%rsp),%ecx
mov    %ecx,0x6(%rax)
mov    0x9(%rsp),%cl
mov    %cl,0xa(%rax)
movb   $0x2d,0x5(%rax)
mov    0xe(%rsp),%cl
mov    %cl,0x10(%rax)
mov    0xa(%rsp),%ecx
mov    %ecx,0xc(%rax)
movb   $0x2d,0xb(%rax)
mov    0xf(%rsp),%ecx
mov    %ecx,0x12(%rax)
mov    0x13(%rsp),%cl
mov    %cl,0x16(%rax)
movb   $0x2d,0x11(%rax)
mov    0x14(%rsp),%ecx
mov    %ecx,0x18(%rax)
mov    0x18(%rsp),%cl
mov    %cl,0x1c(%rax)
movb   $0x2d,0x17(%rax)
mov    0x1d(%rsp),%cl
mov    %cl,0x22(%rax)
mov    0x19(%rsp),%ecx
mov    %ecx,0x1e(%rax)
movb   $0x2d,0x1d(%rax)
mov    0x22(%rsp),%cl
mov    %cl,0x28(%rax)
mov    0x1e(%rsp),%ecx
mov    %ecx,0x24(%rax)
movb   $0x2d,0x23(%rax)
mov    0x27(%rsp),%cl
mov    %cl,0x2e(%rax)
mov    0x23(%rsp),%ecx
mov    %ecx,0x2a(%rax)
movb   $0x2d,0x29(%rax)
add    $0xb0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
define i8* @lic_getmid() {
%1 = alloca i8*
%2 = alloca [128 x i8]
%3 = alloca [40 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @stderr
%8 = call i32 @fclose(i32 %7)
%9 = bitcast [128 x i8]* %2 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%11 = call i64 @get_uuid_by_partition(i8* %10, i32 128)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%15 = call i64 @get_uuid_by_docker_cpuset(i8* %14, i32 128)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* null, i8** %1
br label %71
18: ; preds = %13
br label %19
19: ; preds = %18, %0
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @revstr(i8* %20, i32 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%28 = call i32 @sha1sum(i8* %24, i32 %26, i8* %27)
%29 = call i8* @calloc(i32 47, i32 1)
store i8* %29, i8** %4
store i32 0, i32* %5
br label %30
30: ; preds = %66, %19
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 8
br i1 %32, label %33, label %69
33: ; preds = %30
store i32 0, i32* %6
br label %34
34: ; preds = %54, %33
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 5
br i1 %36, label %37, label %57
37: ; preds = %34
%38 = load i32, i32* %5
%39 = mul nsw i32 %38, 5
%40 = load i32, i32* %6
%41 = add nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %4
%46 = load i32, i32* %5
%47 = mul nsw i32 %46, 5
%48 = load i32, i32* %5
%49 = add nsw i32 %47, %48
%50 = load i32, i32* %6
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %45, i64 %52
store i8 %44, i8* %53
br label %54
54: ; preds = %37
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %34
57: ; preds = %34
%58 = load i8*, i8** %4
%59 = load i32, i32* %5
%60 = mul nsw i32 %59, 5
%61 = load i32, i32* %5
%62 = add nsw i32 %60, %61
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %58, i64 %64
store i8 45, i8* %65
br label %66
66: ; preds = %57
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %30
69: ; preds = %30
%70 = load i8*, i8** %4
store i8* %70, i8** %1
br label %71
71: ; preds = %69, %17
%72 = load i8*, i8** %1
ret i8* %72
}

LLVM IR (-O2):
@stderr = global i32 0
define noalias i8* @lic_getmid() {
%1 = alloca [128 x i8]
%2 = alloca [40 x i8]
%3 = load i32, i32* @stderr
%4 = tail call i32 @fclose(i32 %3)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = call i64 @get_uuid_by_partition(i8* %5, i32 128)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i64 @get_uuid_by_docker_cpuset(i8* %5, i32 128)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %40
11: ; preds = %8, %0
%12 = call i32 @strlen(i8* %5)
%13 = call i32 @revstr(i8* %5, i32 %12)
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen(i8* %5)
%16 = call i32 @sha1sum(i8* %5, i32 %15, i8* %14)
%17 = call dereferenceable_or_null(47) i8* @calloc(i32 47, i32 1)
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8 45, i8* %18
%19 = getelementptr i8, i8* %17, i64 6
%20 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 5
%21 = getelementptr inbounds i8, i8* %17, i64 5
store i8 45, i8* %21
%22 = getelementptr i8, i8* %17, i64 12
%23 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 10
%24 = getelementptr inbounds i8, i8* %17, i64 11
store i8 45, i8* %24
%25 = getelementptr i8, i8* %17, i64 18
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 15
%27 = getelementptr inbounds i8, i8* %17, i64 17
store i8 45, i8* %27
%28 = getelementptr i8, i8* %17, i64 24
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 20
%30 = getelementptr inbounds i8, i8* %17, i64 23
store i8 45, i8* %30
%31 = getelementptr i8, i8* %17, i64 30
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 25
%33 = getelementptr inbounds i8, i8* %17, i64 29
store i8 45, i8* %33
%34 = getelementptr i8, i8* %17, i64 36
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 30
%36 = getelementptr inbounds i8, i8* %17, i64 35
store i8 45, i8* %36
%37 = getelementptr i8, i8* %17, i64 42
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 35
%39 = getelementptr inbounds i8, i8* %17, i64 41
store i8 45, i8* %39
br label %40
40: ; preds = %8, %11
%41 = phi i8* [ %17, %11 ], [ null, %8 ]
ret i8* %41
}