#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
uint8_t pick_node() {
  int node;
  printf("Multi-Sensor Node   :1\n");
  printf("Wall-Plug           :2\n");
  printf("Lamp Holder         :3\n");
  printf("Flood Detector      :4\n");
  printf("Select Device : ");
  scanf("%d", &node);
  switch (node) {
  case 1:
    node = 0x02;
    break;
  case 2:
    node = 0x03;
    break;
  case 3:
    node = 0x04;
    break;
  case 4:
    node = 0x05;
    break;
  default:
    printf("invalid node\n");
    node = 1;
    break;
  }
  return (uint8_t)node;
}


x86 assembly (clang, -O0):
<pick_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
call   1030 <printf@plt>
lea    0xef9(%rip),%rdi
call   1030 <printf@plt>
lea    0xf05(%rip),%rdi
call   1030 <printf@plt>
lea    0xf11(%rip),%rdi
call   1030 <printf@plt>
lea    0xf16(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11cd <pick_node+0xad>
mov    -0x10(%rbp),%rax
lea    0xe6c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x4(%rbp)
jmp    11e0 <pick_node+0xc0>
movl   $0x3,-0x4(%rbp)
jmp    11e0 <pick_node+0xc0>
movl   $0x4,-0x4(%rbp)
jmp    11e0 <pick_node+0xc0>
movl   $0x5,-0x4(%rbp)
jmp    11e0 <pick_node+0xc0>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick_node>:
push   %rax
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x4,%ecx
jae    118f <pick_node+0x5f>
add    $0x1,%eax
pop    %rcx
ret
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Multi-Sensor Node :1\0A\00"
@.str.1 = [24 x i8] c"Wall-Plug :2\0A\00"
@.str.2 = [24 x i8] c"Lamp Holder :3\0A\00"
@.str.3 = [24 x i8] c"Flood Detector :4\0A\00"
@.str.4 = [17 x i8] c"Select Device : \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [14 x i8] c"invalid node\0A\00"
define i32 @pick_node() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
switch i32 %8, label %13 [
i32 1, label %9
i32 2, label %10
i32 3, label %11
i32 4, label %12
]
9: ; preds = %0
store i32 2, i32* %1
br label %15
10: ; preds = %0
store i32 3, i32* %1
br label %15
11: ; preds = %0
store i32 4, i32* %1
br label %15
12: ; preds = %0
store i32 5, i32* %1
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %15
15: ; preds = %13, %12, %11, %10, %9
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str.4 = [17 x i8] c"Select Device : \00"
@.str.5 = [3 x i8] c"%d\00"
@str = [23 x i8] c"Multi-Sensor Node :1\00"
@str.7 = [23 x i8] c"Wall-Plug :2\00"
@str.8 = [23 x i8] c"Lamp Holder :3\00"
@str.9 = [23 x i8] c"Flood Detector :4\00"
@str.10 = [13 x i8] c"invalid node\00"
define i32 @pick_node() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = add i32 %9, -1
%11 = icmp ult i32 %10, 4
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
br label %16
14: ; preds = %0
%15 = add i32 %9, 1
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ 1, %12 ], [ %15, %14 ]
ret i32 %17
}