#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_all(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_all(keys);
  int c = getch();
  int i = 0;
  while (1) {
    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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1060 <clear_all@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <add_data@plt>
mov    -0xc(%rbp),%esi
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0xc(%rbp)
jmp    118e <test+0x3e>

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <clear_all@plt>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%ebx
lea    0xead(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
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
jmp    1190 <test+0x40>

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_all(i32* %7)
%9 = call i32 (...) @getch()
store i32 %9, i32* %3
store i32 0, i32* %4
br label %10
10: ; preds = %1, %10
%11 = load i32*, i32** %2
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = call i32 @add_data(i32* %11, i32 %12, i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = call i32 (...) @getch()
store i32 %19, i32* %3
br label %10
}

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_all(i32* %0)
%5 = tail call i32 (...) @getch()
br label %6
6: ; preds = %6, %1
%7 = phi i32 [ %5, %1 ], [ %12, %6 ]
%8 = phi i32 [ 0, %1 ], [ %11, %6 ]
%9 = tail call i32 @add_data(i32* %0, i32 %8, i32 %7)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%11 = add nuw nsw i32 %8, 1
%12 = tail call i32 (...) @getch()
br label %6
}