#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
scalar_t__ tnlIsOption(int);
int /*<<< orphan*/ tnlRequestSubOption(int);
int /*<<< orphan*/ tnlSendSubOption(int, char *);
int /*<<< orphan*/ toupper(int /*<<< orphan*/);
int cmdDevice(int argc, char *argv[]) {
  char buf[256], *cp, *cp1;
  if (tnlIsOption(130)) {
    if (argc == 2) {
      for (cp = argv[1], cp1 = buf; *cp;)
        *(cp1++) = toupper(*(cp++));
      *cp1 = '\0';
      if (strcmp(buf, "SELECT") == 0)
        tnlRequestSubOption(131);
      else
        tnlSendSubOption(130, argv[1]);
    } else if (argc == 1)
      tnlRequestSubOption(130);
    else
      fprintf(stderr, "\rusage: device [<settings>]\n\r");
  } else
    fprintf(stderr, "\rOption DEVICE is disabled\n\r");
  return (0);
}


x86 assembly (clang, -O0):
<cmdDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x82,%edi
call   1070 <tnlIsOption@plt>
cmp    $0x0,%rax
je     127d <cmdDevice+0x11d>
cmpl   $0x2,-0x4(%rbp)
jne    1245 <cmdDevice+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f8 <cmdDevice+0x98>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x120(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x120(%rbp)
mov    %cl,(%rax)
jmp    11ad <cmdDevice+0x4d>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    122e <cmdDevice+0xce>
mov    $0x83,%edi
call   1080 <tnlRequestSubOption@plt>
jmp    1240 <cmdDevice+0xe0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x82,%edi
call   1050 <tnlSendSubOption@plt>
jmp    1278 <cmdDevice+0x118>
cmpl   $0x1,-0x4(%rbp)
jne    125e <cmdDevice+0xfe>
mov    $0x82,%edi
call   1080 <tnlRequestSubOption@plt>
jmp    1273 <cmdDevice+0x113>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1278 <cmdDevice+0x118>
jmp    1292 <cmdDevice+0x132>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdDevice>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x82,%edi
call   1070 <tnlIsOption@plt>
test   %rax,%rax
je     11e1 <cmdDevice+0x81>
cmp    $0x1,%ebp
je     11f3 <cmdDevice+0x93>
cmp    $0x2,%ebp
jne    11ff <cmdDevice+0x9f>
mov    0x8(%r14),%rbp
mov    0x0(%rbp),%al
mov    %rsp,%rbx
test   %al,%al
je     11ba <cmdDevice+0x5a>
add    $0x1,%rbp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11a0 <cmdDevice+0x40>
movb   $0x0,(%rbx)
lea    0xe3c(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1222 <cmdDevice+0xc2>
mov    0x8(%r14),%rsi
mov    $0x82,%edi
call   1050 <tnlSendSubOption@plt>
jmp    1214 <cmdDevice+0xb4>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
jmp    120f <cmdDevice+0xaf>
mov    $0x82,%edi
call   1080 <tnlRequestSubOption@plt>
jmp    1214 <cmdDevice+0xb4>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x83,%edi
call   1080 <tnlRequestSubOption@plt>
jmp    1214 <cmdDevice+0xb4>

LLVM IR (-O0):
@.str = [7 x i8] c"SELECT\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"\0Dusage: device [<settings>]\0A\0D\00"
@.str.2 = [29 x i8] c"\0DOption DEVICE is disabled\0A\0D\00"
define i32 @cmdDevice(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i64 @tnlIsOption(i32 130)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %54
10: ; preds = %2
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %44
13: ; preds = %10
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8* %17, i8** %7
br label %18
18: ; preds = %22, %13
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = call i32 @toupper(i32 %26)
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %7
store i8 %28, i8* %29
br label %18
31: ; preds = %18
%32 = load i8*, i8** %7
store i8 0, i8* %32
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @tnlRequestSubOption(i32 131)
br label %43
38: ; preds = %31
%39 = load i8**, i8*** %4
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @tnlSendSubOption(i32 130, i8* %41)
br label %43
43: ; preds = %38, %36
br label %53
44: ; preds = %10
%45 = load i32, i32* %3
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @tnlRequestSubOption(i32 130)
br label %52
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %49, %47
br label %53
53: ; preds = %52, %43
br label %57
54: ; preds = %2
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %54, %53
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"SELECT\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"\0Dusage: device [<settings>]\0A\0D\00"
@.str.2 = [29 x i8] c"\0DOption DEVICE is disabled\0A\0D\00"
define i32 @cmdDevice(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @tnlIsOption(i32 130)
%6 = icmp eq i64 %5, 0
br i1 %6, label %38, label %7
7: ; preds = %2
switch i32 %0, label %35 [
i32 2, label %8
i32 1, label %33
]
8: ; preds = %7
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %8, %13
%14 = phi i8 [ %22, %13 ], [ %11, %8 ]
%15 = phi i8* [ %21, %13 ], [ %4, %8 ]
%16 = phi i8* [ %17, %13 ], [ %10, %8 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = sext i8 %14 to i32
%19 = tail call i32 @toupper(i32 %18)
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %20, i8* %15
%22 = load i8, i8* %17
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %13, %8
%25 = phi i8* [ %4, %8 ], [ %21, %13 ]
store i8 0, i8* %25
%26 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @tnlRequestSubOption(i32 131)
br label %41
30: ; preds = %24
%31 = load i8*, i8** %9
%32 = call i32 @tnlSendSubOption(i32 130, i8* %31)
br label %41
33: ; preds = %7
%34 = tail call i32 @tnlRequestSubOption(i32 130)
br label %41
35: ; preds = %7
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %41
38: ; preds = %2
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %30, %28, %35, %33, %38
ret i32 0
}