#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*/ info(int /*<<< orphan*/, char *, int, int);
int parse_uint(char *, int, char *, int);
int send_then_recv(int, char, char *, int, int, ...);
int strlen(char *);
char tolower(char);
int handle_heat_common(int devfd, int nodeid, char *arg, int mode) {
  int setpoint = parse_uint(arg, 2, "setpoint", 99);
  int units = 1, ret;
  if (strlen(arg) >= 3 && tolower(arg[2]) == 'c')
    units = 0;
  if (setpoint) {
    if (units)
      ret = send_then_recv(devfd, 'X', ">N%03dSE67,1,%d,9,%d", nodeid, mode,
                           setpoint);
    else
      ret = send_then_recv(devfd, 'X', ">N%03dSE67,1,%d,17,%d", nodeid, mode,
                           setpoint);
    if (ret != 0) {
      info(0, "node %d returned X%03x for SETPOINT command\n", nodeid, ret);
      return -ret;
    }
  } else {
    mode = 0;
  }
  ret = send_then_recv(devfd, 'X', ">N%03dSE64,1,%d", nodeid, mode);
  if (ret != 0) {
    info(0, "node %d returned X%03x for MODE command\n", nodeid, ret);
    return -ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_heat_common>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
lea    0xe8b(%rip),%rdx
mov    $0x63,%ecx
call   1070 <parse_uint@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     11bb <handle_heat_common+0x6b>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
cmp    $0x63,%eax
jne    11bb <handle_heat_common+0x6b>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     124c <handle_heat_common+0xfc>
cmpl   $0x0,-0x24(%rbp)
je     11f8 <handle_heat_common+0xa8>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x58,%esi
lea    0xe20(%rip),%rdx
mov    $0x0,%al
call   1030 <send_then_recv@plt>
mov    %eax,-0x28(%rbp)
jmp    121c <handle_heat_common+0xcc>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x58,%esi
lea    0xe0c(%rip),%rdx
mov    $0x0,%al
call   1030 <send_then_recv@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1247 <handle_heat_common+0xf7>
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %edi,%edi
lea    0xdff(%rip),%rsi
call   1060 <info@plt>
xor    %eax,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a5 <handle_heat_common+0x155>
jmp    1253 <handle_heat_common+0x103>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    $0x58,%esi
lea    0xdf8(%rip),%rdx
mov    $0x0,%al
call   1030 <send_then_recv@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     129e <handle_heat_common+0x14e>
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %edi,%edi
lea    0xde5(%rip),%rsi
call   1060 <info@plt>
xor    %eax,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a5 <handle_heat_common+0x155>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_heat_common>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0xe95(%rip),%rdx
mov    %rbp,%rdi
mov    $0x2,%esi
mov    $0x63,%ecx
call   1070 <parse_uint@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     11af <handle_heat_common+0x5f>
movsbl 0x2(%rbp),%edi
call   1050 <tolower@plt>
test   %ebx,%ebx
je     11ef <handle_heat_common+0x9f>
cmp    $0x63,%al
lea    0xe7c(%rip),%rax
lea    0xe60(%rip),%rdx
cmove  %rax,%rdx
jmp    11ba <handle_heat_common+0x6a>
test   %ebx,%ebx
je     11ef <handle_heat_common+0x9f>
lea    0xe4f(%rip),%rdx
mov    %r14d,%edi
mov    $0x58,%esi
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1030 <send_then_recv@plt>
test   %eax,%eax
je     11f2 <handle_heat_common+0xa2>
mov    %eax,%ebx
lea    0xe55(%rip),%rsi
xor    %edi,%edi
mov    %r15d,%edx
mov    %eax,%ecx
call   1060 <info@plt>
neg    %ebx
jmp    122d <handle_heat_common+0xdd>
xor    %r12d,%r12d
lea    0xe68(%rip),%rdx
xor    %ebx,%ebx
mov    %r14d,%edi
mov    $0x58,%esi
mov    %r15d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1030 <send_then_recv@plt>
test   %eax,%eax
je     122d <handle_heat_common+0xdd>
mov    %eax,%ebp
lea    0xe54(%rip),%rsi
xor    %edi,%edi
mov    %r15d,%edx
mov    %eax,%ecx
call   1060 <info@plt>
neg    %ebp
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"setpoint\00"
@.str.1 = [21 x i8] c">N%03dSE67,1,%d,9,%d\00"
@.str.2 = [22 x i8] c">N%03dSE67,1,%d,17,%d\00"
@.str.3 = [45 x i8] c"node %d returned X%03x for SETPOINT command\0A\00"
@.str.4 = [16 x i8] c">N%03dSE64,1,%d\00"
@.str.5 = [41 x i8] c"node %d returned X%03x for MODE command\0A\00"
define i32 @handle_heat_common(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %8
%14 = call i32 @parse_uint(i8* %13, i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 99)
store i32 %14, i32* %10
store i32 1, i32* %11
%15 = load i8*, i8** %8
%16 = call i32 @strlen(i8* %15)
%17 = icmp sge i32 %16, 3
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 99
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 0, i32* %11
br label %26
26: ; preds = %25, %18, %4
%27 = load i32, i32* %10
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %54
29: ; preds = %26
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = call i32 (i32, i8, i8*, i32, i32, ...) @send_then_recv(i32 %33, i8 signext 88, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
store i32 %37, i32* %12
br label %44
38: ; preds = %29
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = call i32 (i32, i8, i8*, i32, i32, ...) @send_then_recv(i32 %39, i8 signext 88, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %12
br label %44
44: ; preds = %38, %32
%45 = load i32, i32* %12
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load i32, i32* %7
%49 = load i32, i32* %12
%50 = call i32 @info(i32 0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %49)
%51 = load i32, i32* %12
%52 = sub nsw i32 0, %51
store i32 %52, i32* %5
br label %69
53: ; preds = %44
br label %55
54: ; preds = %26
store i32 0, i32* %9
br label %55
55: ; preds = %54, %53
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = load i32, i32* %9
%59 = call i32 (i32, i8, i8*, i32, i32, ...) @send_then_recv(i32 %56, i8 signext 88, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %57, i32 %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %55
%63 = load i32, i32* %7
%64 = load i32, i32* %12
%65 = call i32 @info(i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %63, i32 %64)
%66 = load i32, i32* %12
%67 = sub nsw i32 0, %66
store i32 %67, i32* %5
br label %69
68: ; preds = %55
store i32 0, i32* %5
br label %69
69: ; preds = %68, %62, %47
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
@.str = [9 x i8] c"setpoint\00"
@.str.1 = [21 x i8] c">N%03dSE67,1,%d,9,%d\00"
@.str.2 = [22 x i8] c">N%03dSE67,1,%d,17,%d\00"
@.str.3 = [45 x i8] c"node %d returned X%03x for SETPOINT command\0A\00"
@.str.4 = [16 x i8] c">N%03dSE64,1,%d\00"
@.str.5 = [41 x i8] c"node %d returned X%03x for MODE command\0A\00"
define i32 @handle_heat_common(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @parse_uint(i8* %2, i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 99)
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %2, i64 2
%10 = load i8, i8* %9
%11 = tail call signext i8 @tolower(i8 signext %10)
%12 = icmp eq i32 %5, 0
br i1 %12, label %25, label %15
13: ; preds = %4
%14 = icmp eq i32 %5, 0
br i1 %14, label %25, label %18
15: ; preds = %8
%16 = icmp eq i8 %11, 99
%17 = select i1 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0)
br label %18
18: ; preds = %15, %13
%19 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %13 ], [ %17, %15 ]
%20 = tail call i32 (i32, i8, i8*, i32, i32, ...) @send_then_recv(i32 %0, i8 signext 88, i8* %19, i32 %1, i32 %3, i32 %5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = tail call i32 @info(i32 0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %20)
%24 = sub nsw i32 0, %20
br label %32
25: ; preds = %13, %8, %18
%26 = phi i32 [ %3, %18 ], [ 0, %8 ], [ 0, %13 ]
%27 = tail call i32 (i32, i8, i8*, i32, i32, ...) @send_then_recv(i32 %0, i8 signext 88, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %1, i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = tail call i32 @info(i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %1, i32 %27)
%31 = sub nsw i32 0, %27
br label %32
32: ; preds = %25, %29, %22
%33 = phi i32 [ %24, %22 ], [ %31, %29 ], [ 0, %25 ]
ret i32 %33
}