#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 get_rid(char *, long);
int /*<<< orphan*/ printf(char *, long);
int set_rid(char *, long, int, char **);
scalar_t__ strcmp(char *, char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  char *dev;
  int set;
  long int rid;
  if (argc < 4) {
    usage();
    return -1;
  }
  dev = argv[1];
  if (strcmp(argv[2], "set") == 0)
    set = 1;
  else if (strcmp(argv[2], "get") == 0)
    set = 0;
  else {
    usage();
    return -1;
  }
  rid = strtol(argv[3], NULL, 16);
  if (rid < 0 || rid > 65535) {
    usage();
    printf("\nInvalid rid 0x%lx\n", rid);
    return -1;
  }
  if (set)
    return set_rid(dev, rid, argc - 4, &argv[4]);
  else
    return get_rid(dev, rid);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1193 <main+0x33>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c9 <main+0x69>
movl   $0x1,-0x1c(%rbp)
jmp    120b <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f3 <main+0x93>
movl   $0x0,-0x1c(%rbp)
jmp    1206 <main+0xa6>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x13e>
jmp    120b <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jl     123e <main+0xde>
cmpq   $0xffff,-0x28(%rbp)
jle    1261 <main+0x101>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x28(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x13e>
cmpl   $0x0,-0x1c(%rbp)
je     128e <main+0x12e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
sub    $0x4,%edx
mov    -0x10(%rbp),%rcx
add    $0x20,%rcx
call   1080 <set_rid@plt>
mov    %eax,-0x4(%rbp)
jmp    129e <main+0x13e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <get_rid@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jle    119f <main+0x3f>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b6 <main+0x56>
mov    0x10(%rbx),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f2 <main+0x92>
xor    %eax,%eax
call   1060 <usage@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,%r15
cmp    $0xffff,%rax
ja     120d <main+0xad>
add    $0xfffffffc,%ebp
add    $0x20,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <set_rid@plt>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,%r15
cmp    $0x10000,%rax
jb     1225 <main+0xc5>
xor    %eax,%eax
call   1060 <usage@plt>
lea    0xded(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
jmp    11a6 <main+0x46>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <get_rid@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"set\00"
@.str.1 = [4 x i8] c"get\00"
@.str.2 = [20 x i8] c"\0AInvalid rid 0x%lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %62
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 1, i32* %7
br label %33
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %7
br label %32
30: ; preds = %23
%31 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %62
32: ; preds = %29
br label %33
33: ; preds = %32, %22
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i64 @strtol(i8* %36, i32* null, i32 16)
store i64 %37, i64* %8
%38 = load i64, i64* %8
%39 = icmp slt i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %33
%41 = load i64, i64* %8
%42 = icmp sgt i64 %41, 65535
br i1 %42, label %43, label %47
43: ; preds = %40, %33
%44 = call i32 (...) @usage()
%45 = load i64, i64* %8
%46 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %45)
store i32 -1, i32* %3
br label %62
47: ; preds = %40
%48 = load i32, i32* %7
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %47
%51 = load i8*, i8** %6
%52 = load i64, i64* %8
%53 = load i32, i32* %4
%54 = sub nsw i32 %53, 4
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 4
%57 = call i32 @set_rid(i8* %51, i64 %52, i32 %54, i8** %56)
store i32 %57, i32* %3
br label %62
58: ; preds = %47
%59 = load i8*, i8** %6
%60 = load i64, i64* %8
%61 = call i32 @get_rid(i8* %59, i64 %60)
store i32 %61, i32* %3
br label %62
62: ; preds = %58, %50, %43, %30, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [4 x i8] c"set\00"
@.str.1 = [4 x i8] c"get\00"
@.str.2 = [20 x i8] c"\0AInvalid rid 0x%lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %39
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = load i8*, i8** %9
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = tail call i32 (...) @usage()
br label %39
19: ; preds = %6
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i64 @strtol(i8* nocapture %21, i32* null, i32 16)
%23 = icmp ugt i64 %22, 65535
br i1 %23, label %29, label %33
24: ; preds = %13
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = tail call i64 @strtol(i8* nocapture %26, i32* null, i32 16)
%28 = icmp ugt i64 %27, 65535
br i1 %28, label %29, label %37
29: ; preds = %24, %19
%30 = phi i64 [ %27, %24 ], [ %22, %19 ]
%31 = tail call i32 (...) @usage()
%32 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %30)
br label %39
33: ; preds = %19
%34 = add nsw i32 %0, -4
%35 = getelementptr inbounds i8*, i8** %1, i64 4
%36 = tail call i32 @set_rid(i8* %8, i64 %22, i32 %34, i8** %35)
br label %39
37: ; preds = %24
%38 = tail call i32 @get_rid(i8* %8, i64 %27)
br label %39
39: ; preds = %37, %33, %29, %17, %4
%40 = phi i32 [ -1, %4 ], [ -1, %29 ], [ %36, %33 ], [ %38, %37 ], [ -1, %17 ]
ret i32 %40
}