#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 */
unsigned long get4l(unsigned char const *, int);
unsigned long long get6h(unsigned char const *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *decodesid(const unsigned char *sid) {
  char *str;
  int i;
  unsigned long long auth;
  unsigned long subauth;
  str = (char *)malloc(80);
  if (str) {
    strcpy(str, "S");
    sprintf(&str[strlen(str)], "-%d", sid[0]);
    auth = get6h(sid, 2);
    sprintf(&str[strlen(str)], "-%llu", auth);
    for (i = 0; (i < 8) && (i < sid[1]); i++) {
      subauth = get4l(sid, 8 + 4 * i);
      sprintf(&str[strlen(str)], "-%lu", subauth);
    }
  }
  return (str);
}


x86 assembly (clang, -O0):
<decodesid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     128a <decodesid+0x12a>
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
lea    0xe4a(%rip),%rsi
movzbl (%rax),%edx
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1070 <get6h@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
mov    -0x20(%rbp),%rax
lea    0xe11(%rip),%rsi
movzbl %al,%edx
call   1080 <sprintf@plt>
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x8,-0x14(%rbp)
mov    %al,-0x39(%rbp)
jge    1226 <decodesid+0xc6>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1236 <decodesid+0xd6>
jmp    1285 <decodesid+0x125>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x2,%esi
add    $0x8,%esi
call   1030 <get4l@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rax
lea    0xd9d(%rip),%rsi
movzbl %al,%edx
call   1080 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1204 <decodesid+0xa4>
jmp    128a <decodesid+0x12a>
mov    -0x10(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decodesid>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     137e <decodesid+0x21e>
lea    0xe7b(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl (%r14),%edx
lea    0xe5e(%rip),%rsi
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1070 <get6h@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xe37(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x0,0x1(%r14)
je     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xe07(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x2,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0xc,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xdd1(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x3,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x10,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xd9b(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x4,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x14,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xd65(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x5,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x18,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xd2f(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x6,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x1c,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xcf9(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x7,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r15,1),%rdi
movzbl %bl,%edx
lea    0xcc7(%rip),%rsi
call   1080 <sprintf@plt>
cmpb   $0x8,0x1(%r14)
jb     137e <decodesid+0x21e>
mov    %r14,%rdi
mov    $0x24,%esi
call   1030 <get4l@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
add    %rax,%rdi
movzbl %bl,%edx
lea    0xc93(%rip),%rsi
call   1080 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"S\00"
@.str.1 = [4 x i8] c"-%d\00"
@.str.2 = [6 x i8] c"-%llu\00"
@.str.3 = [5 x i8] c"-%lu\00"
define i8* @decodesid(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
%7 = call i64 @malloc(i32 80)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %60
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %20)
%22 = load i8*, i8** %2
%23 = call i64 @get6h(i8* %22, i32 2)
store i64 %23, i64* %5
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i64, i64* %5
%29 = trunc i64 %28 to i8
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %29)
store i32 0, i32* %4
br label %31
31: ; preds = %56, %11
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 8
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* %4
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = icmp slt i32 %35, %39
br label %41
41: ; preds = %34, %31
%42 = phi i1 [ false, %31 ], [ %40, %34 ]
br i1 %42, label %43, label %59
43: ; preds = %41
%44 = load i8*, i8** %2
%45 = load i32, i32* %4
%46 = mul nsw i32 4, %45
%47 = add nsw i32 8, %46
%48 = call i64 @get4l(i8* %44, i32 %47)
store i64 %48, i64* %6
%49 = load i8*, i8** %3
%50 = load i8*, i8** %3
%51 = call i64 @strlen(i8* %50)
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i64, i64* %6
%54 = trunc i64 %53 to i8
%55 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %54)
br label %56
56: ; preds = %43
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %31
59: ; preds = %41
br label %60
60: ; preds = %59, %1
%61 = load i8*, i8** %3
ret i8* %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"S\00"
@.str.1 = [4 x i8] c"-%d\00"
@.str.2 = [6 x i8] c"-%llu\00"
@.str.3 = [5 x i8] c"-%lu\00"
define i8* @decodesid(i8* %0) {
%2 = tail call i64 @malloc(i32 80)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %81, label %5
5: ; preds = %1
%6 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @strlen(i8* %3)
%8 = getelementptr inbounds i8, i8* %3, i64 %7
%9 = load i8, i8* %0
%10 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %9)
%11 = tail call i64 @get6h(i8* %0, i32 2)
%12 = tail call i64 @strlen(i8* %3)
%13 = getelementptr inbounds i8, i8* %3, i64 %12
%14 = trunc i64 %11 to i8
%15 = tail call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %14)
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %81, label %19
19: ; preds = %5
%20 = tail call i64 @get4l(i8* %0, i32 8)
%21 = tail call i64 @strlen(i8* %3)
%22 = getelementptr inbounds i8, i8* %3, i64 %21
%23 = trunc i64 %20 to i8
%24 = tail call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %23)
%25 = load i8, i8* %16
%26 = icmp ugt i8 %25, 1
br i1 %26, label %27, label %81
27: ; preds = %19
%28 = tail call i64 @get4l(i8* %0, i32 12)
%29 = tail call i64 @strlen(i8* %3)
%30 = getelementptr inbounds i8, i8* %3, i64 %29
%31 = trunc i64 %28 to i8
%32 = tail call i32 @sprintf(i8* %30, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %31)
%33 = load i8, i8* %16
%34 = icmp ugt i8 %33, 2
br i1 %34, label %35, label %81
35: ; preds = %27
%36 = tail call i64 @get4l(i8* %0, i32 16)
%37 = tail call i64 @strlen(i8* %3)
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = trunc i64 %36 to i8
%40 = tail call i32 @sprintf(i8* %38, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %39)
%41 = load i8, i8* %16
%42 = icmp ugt i8 %41, 3
br i1 %42, label %43, label %81
43: ; preds = %35
%44 = tail call i64 @get4l(i8* %0, i32 20)
%45 = tail call i64 @strlen(i8* %3)
%46 = getelementptr inbounds i8, i8* %3, i64 %45
%47 = trunc i64 %44 to i8
%48 = tail call i32 @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %47)
%49 = load i8, i8* %16
%50 = icmp ugt i8 %49, 4
br i1 %50, label %51, label %81
51: ; preds = %43
%52 = tail call i64 @get4l(i8* %0, i32 24)
%53 = tail call i64 @strlen(i8* %3)
%54 = getelementptr inbounds i8, i8* %3, i64 %53
%55 = trunc i64 %52 to i8
%56 = tail call i32 @sprintf(i8* %54, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %55)
%57 = load i8, i8* %16
%58 = icmp ugt i8 %57, 5
br i1 %58, label %59, label %81
59: ; preds = %51
%60 = tail call i64 @get4l(i8* %0, i32 28)
%61 = tail call i64 @strlen(i8* %3)
%62 = getelementptr inbounds i8, i8* %3, i64 %61
%63 = trunc i64 %60 to i8
%64 = tail call i32 @sprintf(i8* %62, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %63)
%65 = load i8, i8* %16
%66 = icmp ugt i8 %65, 6
br i1 %66, label %67, label %81
67: ; preds = %59
%68 = tail call i64 @get4l(i8* %0, i32 32)
%69 = tail call i64 @strlen(i8* %3)
%70 = getelementptr inbounds i8, i8* %3, i64 %69
%71 = trunc i64 %68 to i8
%72 = tail call i32 @sprintf(i8* %70, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %71)
%73 = load i8, i8* %16
%74 = icmp ugt i8 %73, 7
br i1 %74, label %75, label %81
75: ; preds = %67
%76 = tail call i64 @get4l(i8* %0, i32 36)
%77 = tail call i64 @strlen(i8* %3)
%78 = getelementptr inbounds i8, i8* %3, i64 %77
%79 = trunc i64 %76 to i8
%80 = tail call i32 @sprintf(i8* %78, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %79)
br label %81
81: ; preds = %5, %19, %27, %35, %43, %51, %59, %67, %75, %1
ret i8* %3
}