#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*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int const);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *ata_getversionstring(unsigned short ata_version) {
  const int ATAVERSION_LEN = 16;
  char *version = malloc(ATAVERSION_LEN);
  int i;
  if (version == 0) {
    fprintf(stderr, "malloc failed\n");
    return NULL;
  }
  memset(version, 0, ATAVERSION_LEN);
  for (i = 0; i < 15; i++) {
    if ((ata_version >> i) > 0) {
      sprintf(version, "ATA-%d", i);
    }
  }
  return version;
}


x86 assembly (clang, -O0):
<ata_getversionstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movl   $0x10,-0x10(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1191 <ata_getversionstring+0x51>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <ata_getversionstring+0xb2>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf,-0x1c(%rbp)
jge    11ea <ata_getversionstring+0xaa>
movzwl -0xa(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sar    %cl,%eax
cmp    $0x0,%eax
jle    11d7 <ata_getversionstring+0x97>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe3d(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11dc <ata_getversionstring+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <ata_getversionstring+0x68>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ata_getversionstring>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     132d <ata_getversionstring+0x1ed>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
test   %bp,%bp
je     1342 <ata_getversionstring+0x202>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <sprintf@plt>
cmp    $0x1,%bp
je     1342 <ata_getversionstring+0x202>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <sprintf@plt>
cmp    $0x4,%bp
jb     1342 <ata_getversionstring+0x202>
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1060 <sprintf@plt>
cmp    $0x8,%bp
jb     1342 <ata_getversionstring+0x202>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1060 <sprintf@plt>
cmp    $0x10,%bp
jb     1342 <ata_getversionstring+0x202>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <sprintf@plt>
cmp    $0x20,%bp
jb     1342 <ata_getversionstring+0x202>
lea    0xe02(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1060 <sprintf@plt>
cmp    $0x40,%bp
jb     1342 <ata_getversionstring+0x202>
lea    0xde4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1060 <sprintf@plt>
movzwl %bp,%ebp
cmp    $0x80,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xdc1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1060 <sprintf@plt>
cmp    $0x100,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xda1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1060 <sprintf@plt>
cmp    $0x200,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xd81(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1060 <sprintf@plt>
cmp    $0x400,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xd61(%rip),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <sprintf@plt>
cmp    $0x800,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xd45(%rip),%rsi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1060 <sprintf@plt>
cmp    $0x1000,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xd29(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1060 <sprintf@plt>
cmp    $0x2000,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xd0d(%rip),%rsi
mov    %rbx,%rdi
mov    $0xd,%edx
call   1060 <sprintf@plt>
cmp    $0x4000,%ebp
jb     1342 <ata_getversionstring+0x202>
lea    0xcf1(%rip),%rsi
mov    %rbx,%rdi
mov    $0xe,%edx
call   1060 <sprintf@plt>
jmp    1342 <ata_getversionstring+0x202>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [7 x i8] c"ATA-%d\00"
define i8* @ata_getversionstring(i16 zeroext %0) {
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i16 %0, i16* %3
store i32 16, i32* %4
%7 = call i8* @malloc(i32 16)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %35
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = call i32 @memset(i8* %14, i32 0, i32 16)
store i32 0, i32* %6
br label %16
16: ; preds = %30, %13
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 15
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i16, i16* %3
%21 = zext i16 %20 to i32
%22 = load i32, i32* %6
%23 = ashr i32 %21, %22
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %16
33: ; preds = %16
%34 = load i8*, i8** %5
store i8* %34, i8** %2
br label %35
35: ; preds = %33, %10
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [7 x i8] c"ATA-%d\00"
define i8* @ata_getversionstring(i16 zeroext %0) {
%2 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %54
7: ; preds = %1
%8 = tail call i32 @memset(i8* %2, i32 0, i32 16)
%9 = icmp eq i16 %0, 0
br i1 %9, label %54, label %10
10: ; preds = %7
%11 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0)
%12 = icmp eq i16 %0, 1
br i1 %12, label %54, label %13
13: ; preds = %10
%14 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%15 = icmp ult i16 %0, 4
br i1 %15, label %54, label %16
16: ; preds = %13
%17 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
%18 = icmp ult i16 %0, 8
br i1 %18, label %54, label %19
19: ; preds = %16
%20 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = icmp ult i16 %0, 16
br i1 %21, label %54, label %22
22: ; preds = %19
%23 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 4)
%24 = icmp ult i16 %0, 32
br i1 %24, label %54, label %25
25: ; preds = %22
%26 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 5)
%27 = icmp ult i16 %0, 64
br i1 %27, label %54, label %28
28: ; preds = %25
%29 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%30 = icmp ult i16 %0, 128
br i1 %30, label %54, label %31
31: ; preds = %28
%32 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 7)
%33 = icmp ult i16 %0, 256
br i1 %33, label %54, label %34
34: ; preds = %31
%35 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 8)
%36 = icmp ult i16 %0, 512
br i1 %36, label %54, label %37
37: ; preds = %34
%38 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 9)
%39 = icmp ult i16 %0, 1024
br i1 %39, label %54, label %40
40: ; preds = %37
%41 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 10)
%42 = icmp ult i16 %0, 2048
br i1 %42, label %54, label %43
43: ; preds = %40
%44 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 11)
%45 = icmp ult i16 %0, 4096
br i1 %45, label %54, label %46
46: ; preds = %43
%47 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 12)
%48 = icmp ult i16 %0, 8192
br i1 %48, label %54, label %49
49: ; preds = %46
%50 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 13)
%51 = icmp ult i16 %0, 16384
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 14)
br label %54
54: ; preds = %7, %10, %13, %16, %19, %22, %25, %28, %31, %34, %37, %40, %43, %46, %49, %52, %4
ret i8* %2
}