#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*/ strcpy(char *, char *);
void sprinttype(int type, char *names[], char *result) {
  int nr;
  for (nr = 0; (*names[nr] != '\n'); nr++)
    ;
  if (type < nr)
    strcpy(result, names[type]);
  else
    strcpy(result, "UNDEFINED");
}


x86 assembly (clang, -O0):
<sprinttype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1155 <sprinttype+0x45>
jmp    1147 <sprinttype+0x37>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <sprinttype+0x1a>
mov    -0x4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117b <sprinttype+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
jmp    118b <sprinttype+0x7b>
mov    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprinttype>:
mov    %rdx,%r8
mov    $0xffffffff,%eax
mov    %rsi,%rcx
nopl   0x0(%rax,%rax,1)
mov    (%rcx),%rdx
add    $0x1,%eax
add    $0x8,%rcx
cmpb   $0xa,(%rdx)
jne    1120 <sprinttype+0x10>
cmp    %edi,%eax
jle    1142 <sprinttype+0x32>
movslq %edi,%rax
mov    (%rsi,%rax,8),%rsi
mov    %r8,%rdi
jmp    1030 <strcpy@plt>
lea    0xeb7(%rip),%rsi
mov    %r8,%rdi
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"UNDEFINED\00"
define void @sprinttype(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %18, %3
%9 = load i8**, i8*** %5
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %9, i64 %11
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %21
17: ; preds = %8
br label %18
18: ; preds = %17
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %8
21: ; preds = %8
%22 = load i32, i32* %4
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i8**, i8*** %5
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %26, i8* %31)
br label %36
33: ; preds = %21
%34 = load i8*, i8** %6
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %33, %25
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"UNDEFINED\00"
define void @sprinttype(i32 %0, i8** nocapture %1, i8* %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ %10, %4 ], [ 0, %3 ]
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 10
%10 = add nuw i64 %5, 1
br i1 %9, label %11, label %4
11: ; preds = %4
%12 = trunc i64 %5 to i32
%13 = icmp sgt i32 %12, %0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = sext i32 %0 to i64
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
br label %18
18: ; preds = %11, %14
%19 = phi i8* [ %17, %14 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %11 ]
%20 = tail call i32 @strcpy(i8* %2, i8* %19)
ret void
}