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

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ batwarn_set_gamma(double);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char optstring[] = "g:hrv";
  int opt;
  while ((opt = getopt(argc, argv, optstring)) != -1)
    switch (opt) {
    case 'g':
    set_gamma:
      batwarn_set_gamma(atof(optarg));
      return 0;
    case 'r':
      batwarn_set_gamma(1.0);
      return 0;
    case 'v':
      goto version;
    case 'h':
    default:
      goto usage;
    }
  if (argc < 2)
    goto usage;
  optarg = argv[argc - 1];
  goto set_gamma;
usage : {
  char ubuf[] = "gam "
                "- tiny command line utility to change X11 gamma\n"
                "Copyright 2017, Jeffrey E. Bedard\n"
                "gam -["
                "g:hrv"
                "] [GAMMA]\n"
                "[GAMMA]\n"
                "-g GAMMA\tset gamma value\n"
                "-r\t\trestore gamma to 1.0\n"
                "-v\t\tshow gam version\n"
                "-h\t\tshow gam usage\n";
  write(1, ubuf, sizeof(ubuf));
}
version : {
  char vbuf[] = "gam "
                "version 0.1 "
                "\n";
  write(1, vbuf, sizeof(vbuf));
}
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xed9(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xed3(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x16(%rbp),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1215 <main+0xc5>
mov    -0x1c(%rbp),%eax
add    $0xffffff99,%eax
mov    %eax,%ecx
mov    %rcx,-0x118(%rbp)
sub    $0xf,%eax
ja     1210 <main+0xc0>
mov    -0x118(%rbp),%rax
lea    0xe49(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11cd <main+0x7d>
mov    0x2e24(%rip),%rax
mov    (%rax),%rdi
call   1030 <atof@plt>
call   1060 <batwarn_set_gamma@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <main+0x169>
movsd  0xe0b(%rip),%xmm0
call   1060 <batwarn_set_gamma@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <main+0x169>
jmp    1272 <main+0x122>
jmp    1210 <main+0xc0>
jmp    1244 <main+0xf4>
cmpl   $0x2,-0x8(%rbp)
jge    1224 <main+0xd4>
jmp    1244 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
mov    0x2dbc(%rip),%rax
mov    %rcx,(%rax)
jmp    11cd <main+0x7d>
lea    -0xf0(%rbp),%rdi
lea    0xdfe(%rip),%rsi
mov    $0xce,%edx
call   1050 <memcpy@plt>
lea    -0xf0(%rbp),%rsi
mov    $0x1,%edi
mov    $0xce,%edx
call   1040 <write@plt>
mov    0xea7(%rip),%rax
mov    %rax,-0x110(%rbp)
mov    0xea1(%rip),%rax
mov    %rax,-0x108(%rbp)
mov    0xe9b(%rip),%ax
mov    %ax,-0x100(%rbp)
lea    -0x110(%rbp),%rsi
mov    $0x1,%edi
mov    $0x12,%edx
call   1040 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xe8,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movw   $0x76,0xc(%rsp)
movl   $0x72683a67,0x8(%rsp)
72
lea    0x8(%rsp),%rdx
call   1070 <getopt@plt>
cmp    $0x71,%eax
jg     1196 <main+0x46>
cmp    $0xffffffff,%eax
je     11a2 <main+0x52>
cmp    $0x67,%eax
jne    11a7 <main+0x57>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rdi
jmp    1216 <main+0xc6>
cmp    $0x72,%eax
je     11fb <main+0xab>
cmp    $0x76,%eax
je     11d2 <main+0x82>
jmp    11a7 <main+0x57>
cmp    $0x2,%ebx
jge    1205 <main+0xb5>
lea    0xe62(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    $0xce,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0xce,%edx
call   1040 <write@plt>
movaps 0xf07(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0xa,0x20(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
mov    $0x12,%edx
call   1040 <write@plt>
jmp    1220 <main+0xd0>
movsd  0xdfd(%rip),%xmm0
jmp    121b <main+0xcb>
add    $0xffffffff,%ebx
mov    (%r14,%rbx,8),%rdi
mov    0x2de5(%rip),%rax
mov    %rdi,(%rax)
call   1030 <atof@plt>
call   1060 <batwarn_set_gamma@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.optstring = [6 x i8] c"g:hrv\00"
@optarg = global i8* null
@__const.main.ubuf = [206 x i8] c"gam - tiny command line utility to change X11 gamma\0ACopyright 2017, Jeffrey E. Bedard\0Agam -[g:hrv] [GAMMA]\0A[GAMMA]\0A-g GAMMA\09set gamma value\0A-r\09\09restore gamma to 1.0\0A-v\09\09show gam version\0A-h\09\09show gam usage\0A\00"
@__const.main.vbuf = [18 x i8] c"gam version 0.1 \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i8]
%7 = alloca i32
%8 = alloca [206 x i8]
%9 = alloca [18 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [6 x i8]* %6 to i8*
br label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%15 = call i32 @getopt(i32 %12, i8** %13, i8* %14)
store i32 %15, i32* %7
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = load i32, i32* %7
switch i32 %18, label %28 [
i32 103, label %19
i32 114, label %24
i32 118, label %26
i32 104, label %27
]
19: ; preds = %17
br label %20
20: ; preds = %33, %19
%21 = load i8*, i8** @optarg
%22 = call double @atof(i8* %21)
%23 = call i32 @batwarn_set_gamma(double %22)
store i32 0, i32* %3
br label %48
24: ; preds = %17
%25 = call i32 @batwarn_set_gamma(double 1.000000e+00)
store i32 0, i32* %3
br label %48
26: ; preds = %17
br label %44
27: ; preds = %17
br label %28
28: ; preds = %17, %27
br label %40
29: ; preds = %11
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %33
32: ; preds = %29
br label %40
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
%39 = load i8*, i8** %38
store i8* %39, i8** @optarg
br label %20
40: ; preds = %32, %28
%41 = bitcast [206 x i8]* %8 to i8*
%42 = getelementptr inbounds [206 x i8], [206 x i8]* %8, i64 0, i64 0
%43 = call i32 @write(i32 1, i8* %42, i32 206)
br label %44
44: ; preds = %40, %26
%45 = bitcast [18 x i8]* %9 to i8*
%46 = getelementptr inbounds [18 x i8], [18 x i8]* %9, i64 0, i64 0
%47 = call i32 @write(i32 1, i8* %46, i32 18)
store i32 0, i32* %3
br label %48
48: ; preds = %44, %24, %20
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@__const.main.optstring = [6 x i8] c"g:hrv\00"
@optarg = global i8* null
@__const.main.ubuf = [206 x i8] c"gam - tiny command line utility to change X11 gamma\0ACopyright 2017, Jeffrey E. Bedard\0Agam -[g:hrv] [GAMMA]\0A[GAMMA]\0A-g GAMMA\09set gamma value\0A-r\09\09restore gamma to 1.0\0A-v\09\09show gam version\0A-h\09\09show gam usage\0A\00"
@__const.main.vbuf = [18 x i8] c"gam version 0.1 \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [6 x i8]
%4 = alloca [206 x i8]
%5 = alloca [18 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i32 @getopt(i32 %0, i8** %1, i8* %6)
switch i32 %7, label %23 [
i32 -1, label %16
i32 103, label %8
i32 114, label %14
i32 118, label %26
]
8: ; preds = %2
%9 = load i8*, i8** @optarg
br label %10
10: ; preds = %8, %18
%11 = phi i8* [ %9, %8 ], [ %22, %18 ]
%12 = call double @atof(i8* %11)
%13 = call i32 @batwarn_set_gamma(double %12)
br label %29
14: ; preds = %2
%15 = call i32 @batwarn_set_gamma(double 1.000000e+00)
br label %29
16: ; preds = %2
%17 = icmp slt i32 %0, 2
br i1 %17, label %23, label %18
18: ; preds = %16
%19 = add nsw i32 %0, -1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** @optarg
br label %10
23: ; preds = %2, %16
%24 = getelementptr inbounds [206 x i8], [206 x i8]* %4, i64 0, i64 0
%25 = call i32 @write(i32 1, i8* %24, i32 206)
br label %26
26: ; preds = %2, %23
%27 = getelementptr inbounds [18 x i8], [18 x i8]* %5, i64 0, i64 0
%28 = call i32 @write(i32 1, i8* %27, i32 18)
br label %29
29: ; preds = %26, %14, %10
ret i32 0
}