#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 int Mailbox_GetPowerState(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int Command_GetPower_Execute(char **args, unsigned int argCount) {
  if (argCount != 2) {
    printf("Unexpected amount of arguments, type 'help getpower' for help.\n");
    return -1;
  }
  unsigned int deviceId = *args[1] - '0';
  unsigned int powerState = Mailbox_GetPowerState(deviceId);
  if (powerState == -1) {
    printf("Failed to retrieve power state.\n");
    return -1;
  }
  printf("The power state of '%d' is '%d'", deviceId, powerState);
  return 0;
}


x86 assembly (clang, -O0):
<Command_GetPower_Execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
je     1153 <Command_GetPower_Execute+0x33>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <Command_GetPower_Execute+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <Mailbox_GetPowerState@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1193 <Command_GetPower_Execute+0x73>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <Command_GetPower_Execute+0x8e>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Command_GetPower_Execute>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%esi
jne    1164 <Command_GetPower_Execute+0x34>
mov    0x8(%rdi),%rax
movsbl (%rax),%ebx
add    $0xffffffd0,%ebx
mov    %ebx,%edi
call   1050 <Mailbox_GetPowerState@plt>
cmp    $0xffffffff,%eax
je     116d <Command_GetPower_Execute+0x3d>
lea    0xeab(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    117e <Command_GetPower_Execute+0x4e>
lea    0xed5(%rip),%rdi
jmp    1174 <Command_GetPower_Execute+0x44>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Unexpected amount of arguments, type 'help getpower' for help.\0A\00"
@.str.1 = [33 x i8] c"Failed to retrieve power state.\0A\00"
@.str.2 = [32 x i8] c"The power state of '%d' is '%d'\00"
define i32 @Command_GetPower_Execute(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
12: ; preds = %2
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = sub nsw i32 %17, 48
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i32 @Mailbox_GetPowerState(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
25: ; preds = %12
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %25, %23, %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str.2 = [32 x i8] c"The power state of '%d' is '%d'\00"
@str = [32 x i8] c"Failed to retrieve power state.\00"
@str.3 = [63 x i8] c"Unexpected amount of arguments, type 'help getpower' for help.\00"
define i32 @Command_GetPower_Execute(i8** nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.3, i64 0, i64 0))
br label %18
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %0, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add nsw i32 %10, -48
%12 = tail call i32 @Mailbox_GetPowerState(i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %18
16: ; preds = %6
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12)
br label %18
18: ; preds = %14, %16, %4
%19 = phi i32 [ -1, %4 ], [ -1, %14 ], [ 0, %16 ]
ret i32 %19
}