#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 */
struct state {
  int dummy;
};

/* Variables and functions */
char *event_name(struct state *, unsigned short);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ key_down(struct state *, unsigned short);
int /*<<< orphan*/ key_up(struct state *, unsigned short);
int /*<<< orphan*/ show_press(struct state *, unsigned short);
int /*<<< orphan*/ stderr;
void show_rel(struct state *s, unsigned short c, int n) {
  if (n > 3) {
    fprintf(stderr, "%s: reported %d, limiting to 3...\n", event_name(s, c), n);
    n = 3;
  }
  while (n--) {
    key_down(s, c);
    show_press(s, c);
    key_up(s, c);
  }
}


x86 assembly (clang, -O0):
<show_rel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jle    11a5 <show_rel+0x55>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1050 <event_name@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%ecx
lea    0xe67(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x3,-0x10(%rbp)
jmp    11aa <show_rel+0x5a>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     11ea <show_rel+0x9a>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1070 <key_down@plt>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1040 <show_press@plt>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1060 <key_up@plt>
jmp    11aa <show_rel+0x5a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_rel>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%r14
movzwl %si,%ebx
cmp    $0x4,%edx
jl     1193 <show_rel+0x43>
mov    0x2e75(%rip),%rax
mov    (%rax),%r15d
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <event_name@plt>
lea    0xe81(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1030 <fprintf@plt>
mov    $0x3,%ebp
jmp    11a0 <show_rel+0x50>
test   %ebp,%ebp
je     11c3 <show_rel+0x73>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <key_down@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <show_press@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <key_up@plt>
add    $0xffffffff,%ebp
jne    11a0 <show_rel+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.state = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"%s: reported %d, limiting to 3...\0A\00"
define void @show_rel(%struct.state* %0, i16 zeroext %1, i32 %2) {
%4 = alloca %struct.state*
%5 = alloca i16
%6 = alloca i32
store %struct.state* %0, %struct.state** %4
store i16 %1, i16* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp sgt i32 %7, 3
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load %struct.state*, %struct.state** %4
%12 = load i16, i16* %5
%13 = call i8* @event_name(%struct.state* %11, i16 zeroext %12)
%14 = load i32, i32* %6
%15 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
store i32 3, i32* %6
br label %16
16: ; preds = %9, %3
br label %17
17: ; preds = %21, %16
%18 = load i32, i32* %6
%19 = add nsw i32 %18, -1
store i32 %19, i32* %6
%20 = icmp ne i32 %18, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load %struct.state*, %struct.state** %4
%23 = load i16, i16* %5
%24 = call i32 @key_down(%struct.state* %22, i16 zeroext %23)
%25 = load %struct.state*, %struct.state** %4
%26 = load i16, i16* %5
%27 = call i32 @show_press(%struct.state* %25, i16 zeroext %26)
%28 = load %struct.state*, %struct.state** %4
%29 = load i16, i16* %5
%30 = call i32 @key_up(%struct.state* %28, i16 zeroext %29)
br label %17
31: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.state = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"%s: reported %d, limiting to 3...\0A\00"
define void @show_rel(%struct.state* %0, i16 zeroext %1, i32 %2) {
%4 = icmp sgt i32 %2, 3
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i8* @event_name(%struct.state* %0, i16 zeroext %1)
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %2)
br label %11
9: ; preds = %3
%10 = icmp eq i32 %2, 0
br i1 %10, label %20, label %11
11: ; preds = %5, %9
%12 = phi i32 [ %2, %9 ], [ 3, %5 ]
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ %15, %13 ], [ %12, %11 ]
%15 = add nsw i32 %14, -1
%16 = tail call i32 @key_down(%struct.state* %0, i16 zeroext %1)
%17 = tail call i32 @show_press(%struct.state* %0, i16 zeroext %1)
%18 = tail call i32 @key_up(%struct.state* %0, i16 zeroext %1)
%19 = icmp eq i32 %15, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %9
ret void
}