#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ stderr;
int system(char *);
int /*<<< orphan*/ unlink(char *);
void quitxmode(void) {
  char command[34];
  FILE *xsetq;
  int xdelay, xrate;
  xsetq = fopen("/tmp/clhexagon.tmp", "r");
  if (xsetq == NULL || fscanf(xsetq, "%d %d", &xdelay, &xrate) != 2) {
    fputs("Unable to open tmp file, setting default values of "
          "kbdrate (300, 30)\nThey can be repaired by typing "
          "'xset r rate <delay> <rate>'\n",
          stderr);
    xdelay = 300;
    xrate = 30;
  }
  fclose(xsetq);
  sprintf(command, "xset r rate %d %d", xdelay, xrate);
  if (system(command) == -1)
    fputs("Can't call system(), your kbdrate stays screwed\n", stderr);
  unlink("/tmp/clhexagon.tmp");
}


x86 assembly (clang, -O0):
<quitxmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11bb <quitxmode+0x4b>
mov    -0x38(%rbp),%rdi
lea    0xefe(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1070 <fscanf@plt>
cmp    $0x2,%eax
je     11de <quitxmode+0x6e>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x12c,-0x3c(%rbp)
movl   $0x1e,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xe9f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    1224 <quitxmode+0xb4>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <fputs@plt>
lea    0xdd5(%rip),%rdi
call   1030 <unlink@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quitxmode>:
push   %rbx
sub    $0x40,%rsp
lea    0xe84(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ae <quitxmode+0x3e>
lea    0xf0c(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
call   1070 <fscanf@plt>
cmp    $0x2,%eax
je     11d3 <quitxmode+0x63>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x12c,0xc(%rsp)
movl   $0x1e,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0xead(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    1219 <quitxmode+0xa9>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <fputs@plt>
lea    0xde0(%rip),%rdi
call   1030 <unlink@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/clhexagon.tmp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [130 x i8] c"Unable to open tmp file, setting default values of kbdrate (300, 30)\0AThey can be repaired by typing 'xset r rate <delay> <rate>'\0A\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"xset r rate %d %d\00"
@.str.5 = [49 x i8] c"Can't call system(), your kbdrate stays screwed\0A\00"
define void @quitxmode() {
%1 = alloca [34 x i8]
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %8, %0
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 300, i32* %3
store i32 30, i32* %4
br label %15
15: ; preds = %12, %8
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %20)
%22 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%23 = call i32 @system(i8* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %15
%29 = call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/clhexagon.tmp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [130 x i8] c"Unable to open tmp file, setting default values of kbdrate (300, 30)\0AThey can be repaired by typing 'xset r rate <delay> <rate>'\0A\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"xset r rate %d %d\00"
@.str.5 = [49 x i8] c"Can't call system(), your kbdrate stays screwed\0A\00"
define void @quitxmode() {
%1 = alloca [34 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%11 = icmp eq i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %9, %0
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 300, i32* %2
store i32 30, i32* %3
br label %15
15: ; preds = %12, %9
%16 = call i32 @fclose(i32* %7)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32 @system(i8* %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fputs(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %15
%26 = call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret void
}