#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*/ add_data(int *, int, int);
int /*<<< orphan*/ clear_keys(int *);
int getch();
int /*<<< orphan*/ print_keys(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
void test(int keys[8]) {
  puts("Press Ctrl-C to quit....");
  puts("Press Ctrl-D to show keys....");
  clear_keys(keys);
  int c = getch();
  int i = 0;
  while ((c != 4)) {
    add_data(keys, i, c);
    printf("Added %d \n", c);
    i++;
    c = getch();
  }
  print_keys(keys);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1060 <clear_keys@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0xc(%rbp)
je     11de <test+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <add_data@plt>
mov    -0xc(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0xc(%rbp)
jmp    119e <test+0x3e>
mov    -0x8(%rbp),%rdi
call   1080 <print_keys@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <clear_keys@plt>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0x4,%eax
je     11d7 <test+0x77>
mov    %eax,%ebx
lea    0xe98(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <add_data@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%ebx
cmp    $0x4,%eax
jne    11b0 <test+0x50>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <print_keys@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Press Ctrl-C to quit....\00"
@.str.1 = [30 x i8] c"Press Ctrl-D to show keys....\00"
@.str.2 = [11 x i8] c"Added %d \0A\00"
define void @test(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32*, i32** %2
%8 = call i32 @clear_keys(i32* %7)
%9 = call i32 (...) @getch()
store i32 %9, i32* %3
store i32 0, i32* %4
br label %10
10: ; preds = %13, %1
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = call i32 @add_data(i32* %14, i32 %15, i32 %16)
%18 = load i32, i32* %3
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = call i32 (...) @getch()
store i32 %22, i32* %3
br label %10
23: ; preds = %10
%24 = load i32*, i32** %2
%25 = call i32 @print_keys(i32* %24)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Press Ctrl-C to quit....\00"
@.str.1 = [30 x i8] c"Press Ctrl-D to show keys....\00"
@.str.2 = [11 x i8] c"Added %d \0A\00"
define void @test(i32* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @clear_keys(i32* %0)
%5 = tail call i32 (...) @getch()
%6 = icmp eq i32 %5, 4
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ 0, %1 ]
%9 = phi i32 [ %13, %7 ], [ %5, %1 ]
%10 = tail call i32 @add_data(i32* %0, i32 %8, i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%12 = add nuw nsw i32 %8, 1
%13 = tail call i32 (...) @getch()
%14 = icmp eq i32 %13, 4
br i1 %14, label %15, label %7
15: ; preds = %7, %1
%16 = tail call i32 @print_keys(i32* %0)
ret void
}