#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(char **, int, int);
int /*<<< orphan*/ clear_keys(char **);
int getch();
int /*<<< orphan*/ print_keys(char **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
void test(char keys[8][3]) {
  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 %s \n", keys[i]);
    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     11ea <test+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <add_data@plt>
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
imul   $0x3,%rax,%rax
add    %rax,%rsi
lea    0xe6a(%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     11da <test+0x7a>
lea    0xe9a(%rip),%r14
mov    %r15,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <add_data@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getch@plt>
add    $0x1,%ebp
add    $0x3,%rbx
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 %s \0A\00"
define void @test([3 x i8]* %0) {
%2 = alloca [3 x i8]*
%3 = alloca i32
%4 = alloca i32
store [3 x i8]* %0, [3 x i8]** %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 [3 x i8]*, [3 x i8]** %2
%8 = bitcast [3 x i8]* %7 to i8**
%9 = call i32 @clear_keys(i8** %8)
%10 = call i32 (...) @getch()
store i32 %10, i32* %3
store i32 0, i32* %4
br label %11
11: ; preds = %14, %1
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load [3 x i8]*, [3 x i8]** %2
%16 = bitcast [3 x i8]* %15 to i8**
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = call i32 @add_data(i8** %16, i32 %17, i32 %18)
%20 = load [3 x i8]*, [3 x i8]** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %20, i64 %22
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %23, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
%28 = call i32 (...) @getch()
store i32 %28, i32* %3
br label %11
29: ; preds = %11
%30 = load [3 x i8]*, [3 x i8]** %2
%31 = bitcast [3 x i8]* %30 to i8**
%32 = call i32 @print_keys(i8** %31)
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 %s \0A\00"
define void @test([3 x i8]* %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 = bitcast [3 x i8]* %0 to i8**
%5 = tail call i32 @clear_keys(i8** %4)
%6 = tail call i32 (...) @getch()
%7 = icmp eq i32 %6, 4
br i1 %7, label %18, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %15, %8 ], [ 0, %1 ]
%10 = phi i32 [ %16, %8 ], [ %6, %1 ]
%11 = trunc i64 %9 to i32
%12 = tail call i32 @add_data(i8** %4, i32 %11, i32 %10)
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 %9, i64 0
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = add nuw i64 %9, 1
%16 = tail call i32 (...) @getch()
%17 = icmp eq i32 %16, 4
br i1 %17, label %18, label %8
18: ; preds = %8, %1
%19 = tail call i32 @print_keys(i8** %4)
ret void
}