#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 /*<<< orphan*/, char *, int);
int send_then_recv(int, char, char *, int, ...);
int handle_level(int devfd, int nodeid, char *arg) {
  int ret;
  int level = parse_uint(arg, 0, "brightness level", 255);
  if (nodeid == -2)
    ret = send_then_recv(devfd, 'X', ">N,L%03d", level);
  else
    ret = send_then_recv(devfd, 'X', ">N%03dL%03d", nodeid, level);
  if (ret != 0)
    info(0, "node %d returned X%03x for LEVEL command\n", nodeid, ret);
  return ret;
}


x86 assembly (clang, -O0):
<handle_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    0xeb1(%rip),%rdx
mov    $0xff,%ecx
call   1050 <parse_uint@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xfffffffe,-0x8(%rbp)
jne    1187 <handle_level+0x57>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%ecx
mov    $0x58,%esi
lea    0xe99(%rip),%rdx
mov    $0x0,%al
call   1030 <send_then_recv@plt>
mov    %eax,-0x14(%rbp)
jmp    11a7 <handle_level+0x77>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    $0x58,%esi
lea    0xe7d(%rip),%rdx
mov    $0x0,%al
call   1030 <send_then_recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c5 <handle_level+0x95>
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
xor    %edi,%edi
lea    0xe66(%rip),%rsi
call   1040 <info@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_level>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xebf(%rip),%rdx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xff,%ecx
call   1050 <parse_uint@plt>
cmp    $0xfffffffe,%ebx
jne    116e <handle_level+0x3e>
lea    0xeb5(%rip),%rdx
mov    %ebp,%edi
mov    $0x58,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <send_then_recv@plt>
jmp    1188 <handle_level+0x58>
lea    0xea5(%rip),%rdx
mov    %ebp,%edi
mov    $0x58,%esi
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <send_then_recv@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11a0 <handle_level+0x70>
lea    0xe91(%rip),%rsi
xor    %edi,%edi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <info@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"brightness level\00"
@.str.1 = [9 x i8] c">N,L%03d\00"
@.str.2 = [12 x i8] c">N%03dL%03d\00"
@.str.3 = [42 x i8] c"node %d returned X%03x for LEVEL command\0A\00"
define i32 @handle_level(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @parse_uint(i8* %9, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 255)
store i32 %10, i32* %8
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -2
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* %4
%15 = load i32, i32* %8
%16 = call i32 (i32, i8, i8*, i32, ...) @send_then_recv(i32 %14, i8 signext 88, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %7
br label %22
17: ; preds = %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = load i32, i32* %8
%21 = call i32 (i32, i8, i8*, i32, ...) @send_then_recv(i32 %18, i8 signext 88, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
store i32 %21, i32* %7
br label %22
22: ; preds = %17, %13
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = call i32 @info(i32 0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27)
br label %29
29: ; preds = %25, %22
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@.str = [17 x i8] c"brightness level\00"
@.str.1 = [9 x i8] c">N,L%03d\00"
@.str.2 = [12 x i8] c">N%03dL%03d\00"
@.str.3 = [42 x i8] c"node %d returned X%03x for LEVEL command\0A\00"
define i32 @handle_level(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @parse_uint(i8* %2, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 255)
%5 = icmp eq i32 %1, -2
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i32, i8, i8*, i32, ...) @send_then_recv(i32 %0, i8 signext 88, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %10
8: ; preds = %3
%9 = tail call i32 (i32, i8, i8*, i32, ...) @send_then_recv(i32 %0, i8 signext 88, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %4)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @info(i32 0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %11)
br label %15
15: ; preds = %13, %10
ret i32 %11
}