#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 */
double atof(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
double getPower(int fd) {
  char cmd[4], response[8];
  sprintf(cmd, "PC;");
  write(fd, cmd, strlen(cmd));
  usleep(100e3);
  read(fd, response, 6);
  if (response[0] != 'P' || response[1] != 'C') {
    printf("Didn't get a proper reply to 'power' command.\n");
    return 0.;
  }
  response[5] = '\0';
  return atof(response + 2);
}


x86 assembly (clang, -O0):
<getPower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1070 <read@plt>
movsbl -0x18(%rbp),%eax
cmp    $0x50,%eax
jne    11e5 <getPower+0x75>
movsbl -0x17(%rbp),%eax
cmp    $0x43,%eax
je     11fe <getPower+0x8e>
lea    0xe18(%rip),%rdi
call   1060 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1214 <getPower+0xa4>
movb   $0x0,-0x13(%rbp)
lea    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPower>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x3b4350,0x14(%rsp)
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1070 <read@plt>
cmpb   $0x50,0xc(%rsp)
jne    11c4 <getPower+0x64>
cmpb   $0x43,0xd(%rsp)
jne    11c4 <getPower+0x64>
movb   $0x0,0x11(%rsp)
lea    0xe(%rsp),%rdi
call   1040 <atof@plt>
jmp    11d3 <getPower+0x73>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"PC;\00"
@.str.1 = [47 x i8] c"Didn't get a proper reply to 'power' command.\0A\00"
define double @getPower(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = alloca [8 x i8]
store i32 %0, i32* %3
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write(i32 %8, i8* %9, i32 %11)
%13 = call i32 @usleep(i32 100000)
%14 = load i32, i32* %3
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 6)
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 80
br i1 %20, label %26, label %21
21: ; preds = %1
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 67
br i1 %25, label %26, label %28
26: ; preds = %21, %1
%27 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
store double 0.000000e+00, double* %2
br label %33
28: ; preds = %21
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 5
store i8 0, i8* %29
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = call double @atof(i8* %31)
store double %32, double* %2
br label %33
33: ; preds = %28, %26
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@str = [46 x i8] c"Didn't get a proper reply to 'power' command.\00"
define double @getPower(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
store i32 3883856, i32* %2
%6 = call i32 @strlen(i8* %4)
%7 = call i32 @write(i32 %0, i8* %4, i32 %6)
%8 = call i32 @usleep(i32 100000)
%9 = call i32 @read(i32 %0, i8* %5, i32 6)
%10 = load i8, i8* %5
%11 = icmp ne i8 %10, 80
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 67
%15 = select i1 %11, i1 true, i1 %14
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %22
18: ; preds = %1
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 0, i8* %19
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%21 = call double @atof(i8* %20)
br label %22
22: ; preds = %18, %16
%23 = phi double [ 0.000000e+00, %16 ], [ %21, %18 ]
ret double %23
}