#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*/ EVIOCGREP;
int /*<<< orphan*/ EVIOCSREP;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, unsigned int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void set_delay(int in_fd, unsigned int delay) {
  int ret;
  unsigned int repeat[2];
  ret = ioctl(in_fd, EVIOCGREP, repeat);
  if (ret == -1) {
    perror("ioctl");
    fprintf(stderr, "Could not get repeat rate\n");
    exit(EXIT_FAILURE);
  }
  repeat[0] = delay;
  ret = ioctl(in_fd, EVIOCSREP, repeat);
  if (ret == -1) {
    perror("ioctl");
    fprintf(stderr, "Could not set repeat delay\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<set_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119f <set_delay+0x5f>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11f6 <set_delay+0xb6>
lea    0xe32(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_delay>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     117f <set_delay+0x3f>
mov    %ebp,(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     119d <set_delay+0x5d>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
jmp    11b9 <set_delay+0x79>
lea    0xe5c(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EVIOCGREP = global i32 0
@.str = [6 x i8] c"ioctl\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not get repeat rate\0A\00"
@EXIT_FAILURE = global i32 0
@EVIOCSREP = global i32 0
@.str.2 = [28 x i8] c"Could not set repeat delay\0A\00"
define void @set_delay(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @EVIOCGREP
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @ioctl(i32 %7, i32 %8, i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* %4
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %20, i32* %21
%22 = load i32, i32* %3
%23 = load i32, i32* @EVIOCSREP
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%25 = call i32 @ioctl(i32 %22, i32 %23, i32* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %19
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %19
ret void
}

LLVM IR (-O2):
@EVIOCGREP = global i32 0
@.str = [6 x i8] c"ioctl\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not get repeat rate\0A\00"
@EXIT_FAILURE = global i32 0
@EVIOCSREP = global i32 0
@.str.2 = [28 x i8] c"Could not set repeat delay\0A\00"
define void @set_delay(i32 %0, i32 %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = load i32, i32* @EVIOCGREP
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @ioctl(i32 %0, i32 %5, i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
store i32 %1, i32* %6
%16 = load i32, i32* @EVIOCSREP
%17 = call i32 @ioctl(i32 %0, i32 %16, i32* %6)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %15
ret void
}