#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_SetDevicePowerState(unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int Command_SetPower_Execute(char **args, unsigned int argCount) {
  if (argCount != 3) {
    printf("Unexpected amount of parameters, type 'help setpower' for help.\n");
    return -1;
  }
  unsigned int deviceId = *args[1] - '0';
  if (deviceId < 0 || deviceId > 8) {
    printf("Invalid device id, expected values between 0 - 8.\n");
    return -1;
  }
  unsigned int powerState = *args[2] - '0';
  if (powerState < 0 || powerState > 1) {
    printf("Invalid power state, expected 0 (Off) or 1 (On).\n");
    return -1;
  }
  unsigned int res = 0;
  if ((res = Mailbox_SetDevicePowerState(deviceId, powerState)) != 0)
    printf("Failed to set power for device '%d' to '%d'", deviceId, powerState);
  else
    printf("Sucess setting power of device '%d' to '%d'", deviceId, powerState);
  return res;
}


x86 assembly (clang, -O0):
<Command_SetPower_Execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
je     1153 <Command_SetPower_Execute+0x33>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <Command_SetPower_Execute+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jb     1178 <Command_SetPower_Execute+0x58>
cmpl   $0x8,-0x18(%rbp)
jbe    1192 <Command_SetPower_Execute+0x72>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <Command_SetPower_Execute+0x102>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jb     11b7 <Command_SetPower_Execute+0x97>
cmpl   $0x1,-0x1c(%rbp)
jbe    11d1 <Command_SetPower_Execute+0xb1>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <Command_SetPower_Execute+0x102>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <Mailbox_SetDevicePowerState@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1208 <Command_SetPower_Execute+0xe8>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <Command_SetPower_Execute+0xfc>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Command_SetPower_Execute>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%esi
jne    1151 <Command_SetPower_Execute+0x21>
mov    0x8(%rdi),%rax
movsbl (%rax),%ebp
add    $0xffffffd0,%ebp
cmp    $0x9,%ebp
jb     1169 <Command_SetPower_Execute+0x39>
lea    0xf3a(%rip),%rdi
jmp    1158 <Command_SetPower_Execute+0x28>
lea    0xf63(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x10(%rdi),%rax
movsbl (%rax),%r14d
add    $0xffffffd0,%r14d
cmp    $0x2,%r14d
jb     1184 <Command_SetPower_Execute+0x54>
lea    0xed6(%rip),%rdi
jmp    1158 <Command_SetPower_Execute+0x28>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <Mailbox_SetDevicePowerState@plt>
test   %eax,%eax
je     119d <Command_SetPower_Execute+0x6d>
mov    %eax,%ebx
lea    0xe65(%rip),%rdi
jmp    11a6 <Command_SetPower_Execute+0x76>
lea    0xe88(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1162 <Command_SetPower_Execute+0x32>

LLVM IR (-O0):
@.str = [65 x i8] c"Unexpected amount of parameters, type 'help setpower' for help.\0A\00"
@.str.1 = [51 x i8] c"Invalid device id, expected values between 0 - 8.\0A\00"
@.str.2 = [50 x i8] c"Invalid power state, expected 0 (Off) or 1 (On).\0A\00"
@.str.3 = [44 x i8] c"Failed to set power for device '%d' to '%d'\00"
@.str.4 = [44 x i8] c"Sucess setting power of device '%d' to '%d'\00"
define i32 @Command_SetPower_Execute(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = sub nsw i32 %18, 48
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ult i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = load i32, i32* %6
%24 = icmp ugt i32 %23, 8
br i1 %24, label %25, label %27
25: ; preds = %22, %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
27: ; preds = %22
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 48
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ult i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %27
%37 = load i32, i32* %7
%38 = icmp ugt i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %36, %27
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
41: ; preds = %36
store i32 0, i32* %8
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call i32 @Mailbox_SetDevicePowerState(i32 %42, i32 %43)
store i32 %44, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %47, i32 %48)
br label %54
50: ; preds = %41
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %51, i32 %52)
br label %54
54: ; preds = %50, %46
%55 = load i32, i32* %8
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %39, %25, %11
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.3 = [44 x i8] c"Failed to set power for device '%d' to '%d'\00"
@.str.4 = [44 x i8] c"Sucess setting power of device '%d' to '%d'\00"
@str = [49 x i8] c"Invalid power state, expected 0 (Off) or 1 (On).\00"
@str.5 = [50 x i8] c"Invalid device id, expected values between 0 - 8.\00"
@str.6 = [64 x i8] c"Unexpected amount of parameters, type 'help setpower' for help.\00"
define i32 @Command_SetPower_Execute(i8** nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.6, i64 0, i64 0))
br label %31
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 = icmp ugt i32 %11, 8
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.5, i64 0, i64 0))
br label %31
15: ; preds = %6
%16 = getelementptr inbounds i8*, i8** %0, i64 2
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %19, -48
%21 = icmp ugt i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
br label %31
24: ; preds = %15
%25 = tail call i32 @Mailbox_SetDevicePowerState(i32 %11, i32 %20)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %20)
br label %31
29: ; preds = %24
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %20)
br label %31
31: ; preds = %13, %27, %29, %22, %4
%32 = phi i32 [ -1, %4 ], [ -1, %13 ], [ -1, %22 ], [ 0, %29 ], [ %25, %27 ]
ret i32 %32
}