#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*/ free(char *);
char *get_sata_statlog(int);
int get_sata_pwron(int fd) {
  int poweron = -1;
  char *statlog = NULL;
  statlog = get_sata_statlog(fd);
  if (statlog != NULL) {
    poweron = (statlog[16] + (statlog[17] << 8) + (statlog[18] << 16) +
               (statlog[19] << 24));
    free(statlog);
  }
  return poweron;
}


x86 assembly (clang, -O0):
<get_sata_pwron>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <get_sata_statlog@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <get_sata_pwron+0x6c>
mov    -0x10(%rbp),%rax
movsbl 0x10(%rax),%eax
mov    -0x10(%rbp),%rcx
movsbl 0x11(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x12(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x13(%rcx),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sata_pwron>:
push   %rbx
call   1040 <get_sata_statlog@plt>
test   %rax,%rax
je     1154 <get_sata_pwron+0x34>
movsbl 0x10(%rax),%ecx
movsbl 0x11(%rax),%edx
shl    $0x8,%edx
add    %ecx,%edx
movsbl 0x12(%rax),%ecx
shl    $0x10,%ecx
add    %edx,%ecx
movzbl 0x13(%rax),%ebx
shl    $0x18,%ebx
add    %ecx,%ebx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1159 <get_sata_pwron+0x39>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_sata_pwron(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i32 -1, i32* %3
store i8* null, i8** %4
%5 = load i32, i32* %2
%6 = call i8* @get_sata_statlog(i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %34
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 16
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 17
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = shl i32 %17, 8
%19 = add nsw i32 %13, %18
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 18
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = shl i32 %23, 16
%25 = add nsw i32 %19, %24
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 19
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = shl i32 %29, 24
%31 = add nsw i32 %25, %30
store i32 %31, i32* %3
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %9, %1
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @get_sata_pwron(i32 %0) {
%2 = tail call i8* @get_sata_statlog(i32 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 16
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = getelementptr inbounds i8, i8* %2, i64 17
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = shl nsw i32 %10, 8
%12 = add nsw i32 %11, %7
%13 = getelementptr inbounds i8, i8* %2, i64 18
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = shl nsw i32 %15, 16
%17 = add nsw i32 %12, %16
%18 = getelementptr inbounds i8, i8* %2, i64 19
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = shl nuw i32 %20, 24
%22 = add nsw i32 %17, %21
%23 = tail call i32 @free(i8* %2)
br label %24
24: ; preds = %4, %1
%25 = phi i32 [ %22, %4 ], [ -1, %1 ]
ret i32 %25
}