#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 LockMask;
int atoi(char *);
scalar_t__ get_modifier(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ set_modifier(int, int);
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  enum {
    SHOW_USAGE,
    SETCAPSLOCK_ON,
    SETCAPSLOCK_OFF,
    SETCAPSLOCK_TOGGLE,
    GETCAPSLOCK
  };
  int mod = LockMask;
  int action = SHOW_USAGE;
  char *cmd;
  if (argc == 3) {
    mod = 1 << atoi(argv[2]);
  }
  if (argc >= 2) {
    cmd = argv[1];
    if (strcasecmp(cmd, "on") == 0) {
      action = SETCAPSLOCK_ON;
    } else if (strcasecmp(cmd, "off") == 0) {
      action = SETCAPSLOCK_OFF;
    } else if (strcasecmp(cmd, "toggle") == 0) {
      action = SETCAPSLOCK_TOGGLE;
    } else if (strcasecmp(cmd, "get") == 0) {
      action = GETCAPSLOCK;
    }
  }
  if (action == SHOW_USAGE) {
    usage(argv[0]);
    return 1;
  }
  if (action == SETCAPSLOCK_ON) {
    set_modifier(mod, 1);
  }
  if (action == SETCAPSLOCK_OFF) {
    set_modifier(mod, 0);
  }
  if (action == SETCAPSLOCK_TOGGLE) {
    set_modifier(mod, !get_modifier(mod));
  }
  if (action == GETCAPSLOCK) {
    printf("%s\n", get_modifier(mod) ? "on" : "off");
  }
  return 0;
}


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)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11ac <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1269 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11e8 <main+0x88>
movl   $0x1,-0x18(%rbp)
jmp    1264 <main+0x104>
mov    -0x20(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    120e <main+0xae>
movl   $0x2,-0x18(%rbp)
jmp    125f <main+0xff>
mov    -0x20(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1234 <main+0xd4>
movl   $0x3,-0x18(%rbp)
jmp    125a <main+0xfa>
mov    -0x20(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1255 <main+0xf5>
movl   $0x4,-0x18(%rbp)
jmp    125a <main+0xfa>
jmp    125f <main+0xff>
jmp    1264 <main+0x104>
jmp    1269 <main+0x109>
cmpl   $0x0,-0x18(%rbp)
jne    128b <main+0x12b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1322 <main+0x1c2>
cmpl   $0x1,-0x18(%rbp)
jne    12a2 <main+0x142>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <set_modifier@plt>
cmpl   $0x2,-0x18(%rbp)
jne    12b6 <main+0x156>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <set_modifier@plt>
cmpl   $0x3,-0x18(%rbp)
jne    12e4 <main+0x184>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <get_modifier@plt>
mov    -0x24(%rbp),%edi
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
call   1040 <set_modifier@plt>
cmpl   $0x4,-0x18(%rbp)
jne    131b <main+0x1bb>
mov    -0x14(%rbp),%edi
call   1070 <get_modifier@plt>
mov    %rax,%rcx
lea    0xd03(%rip),%rsi
lea    0xcf9(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xcfc(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1186 <main+0x26>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    $0x1,%r12d
mov    %eax,%ecx
shl    %cl,%r12d
jmp    1195 <main+0x35>
cmp    $0x2,%edi
jl     11ef <main+0x8f>
mov    0x2e4e(%rip),%rax
mov    (%rax),%r12d
mov    0x8(%rbx),%rbp
lea    0xe60(%rip),%r14
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11fe <main+0x9e>
lea    0xe4c(%rip),%r15
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     120d <main+0xad>
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     121b <main+0xbb>
lea    0xe2c(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1236 <main+0xd6>
mov    (%rbx),%rdi
call   1060 <usage@plt>
mov    $0x1,%ebx
jmp    1256 <main+0xf6>
mov    %r12d,%edi
mov    $0x1,%esi
call   1040 <set_modifier@plt>
jmp    1254 <main+0xf4>
xor    %ebx,%ebx
mov    %r12d,%edi
xor    %esi,%esi
call   1040 <set_modifier@plt>
jmp    1256 <main+0xf6>
mov    %r12d,%edi
call   1070 <get_modifier@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
mov    %r12d,%edi
call   1040 <set_modifier@plt>
jmp    1254 <main+0xf4>
mov    %r12d,%edi
call   1070 <get_modifier@plt>
test   %rax,%rax
cmove  %r15,%r14
lea    0xdc6(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LockMask = global i32 0
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"off\00"
@.str.2 = [7 x i8] c"toggle\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @LockMask
store i32 %9, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
%17 = shl i32 1, %16
store i32 %17, i32* %6
br label %18
18: ; preds = %12, %2
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 2
br i1 %20, label %21, label %48
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = call i64 @strcasecmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 1, i32* %7
br label %47
29: ; preds = %21
%30 = load i8*, i8** %8
%31 = call i64 @strcasecmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 2, i32* %7
br label %46
34: ; preds = %29
%35 = load i8*, i8** %8
%36 = call i64 @strcasecmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 3, i32* %7
br label %45
39: ; preds = %34
%40 = load i8*, i8** %8
%41 = call i64 @strcasecmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 4, i32* %7
br label %44
44: ; preds = %43, %39
br label %45
45: ; preds = %44, %38
br label %46
46: ; preds = %45, %33
br label %47
47: ; preds = %46, %28
br label %48
48: ; preds = %47, %18
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @usage(i8* %54)
store i32 1, i32* %3
br label %90
56: ; preds = %48
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %6
%61 = call i32 @set_modifier(i32 %60, i32 1)
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* %7
%64 = icmp eq i32 %63, 2
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %6
%67 = call i32 @set_modifier(i32 %66, i32 0)
br label %68
68: ; preds = %65, %62
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, 3
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i32, i32* %6
%73 = load i32, i32* %6
%74 = call i64 @get_modifier(i32 %73)
%75 = icmp ne i64 %74, 0
%76 = xor i1 %75, true
%77 = zext i1 %76 to i32
%78 = call i32 @set_modifier(i32 %72, i32 %77)
br label %79
79: ; preds = %71, %68
%80 = load i32, i32* %7
%81 = icmp eq i32 %80, 4
br i1 %81, label %82, label %89
82: ; preds = %79
%83 = load i32, i32* %6
%84 = call i64 @get_modifier(i32 %83)
%85 = icmp ne i64 %84, 0
%86 = zext i1 %85 to i64
%87 = select i1 %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%88 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %82, %79
store i32 0, i32* %3
br label %90
90: ; preds = %89, %51
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@LockMask = global i32 0
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"off\00"
@.str.2 = [7 x i8] c"toggle\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = shl nuw i32 1, %7
br label %12
9: ; preds = %2
%10 = load i32, i32* @LockMask
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %27
12: ; preds = %4, %9
%13 = phi i32 [ %8, %4 ], [ %10, %9 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %12
%19 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %18
%22 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %21
%25 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %9, %24
%28 = load i8*, i8** %1
%29 = tail call i32 @usage(i8* %28)
br label %44
30: ; preds = %12
%31 = tail call i32 @set_modifier(i32 %13, i32 1)
br label %44
32: ; preds = %18
%33 = tail call i32 @set_modifier(i32 %13, i32 0)
br label %44
34: ; preds = %21
%35 = tail call i64 @get_modifier(i32 %13)
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = tail call i32 @set_modifier(i32 %13, i32 %37)
br label %44
39: ; preds = %24
%40 = tail call i64 @get_modifier(i32 %13)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %30, %32, %34, %39, %27
%45 = phi i32 [ 1, %27 ], [ 0, %39 ], [ 0, %34 ], [ 0, %32 ], [ 0, %30 ]
ret i32 %45
}