#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 mtwist_state {
  int dummy;
};
typedef int /*<<< orphan*/ robot_patterns;
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char random_digit(struct mtwist_state *);
char random_letter(struct mtwist_state *);
char *random_word(struct mtwist_state *, char **, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void robot_name(struct mtwist_state *mt, char *buffer, int buflen) {
  static char *robot_patterns[] = {"LNLN", "LNLL", "LNNL",
                                   "LLNL", "LLNN", "LNNN"};
  char *pattern =
      random_word(mt, robot_patterns,
                  (sizeof(robot_patterns) / sizeof((robot_patterns)[0])));
  int i;
  char name[20];
  memset(name, 0, sizeof(name));
  for (i = 0; pattern[i]; i++) {
    switch (pattern[i]) {
    case 'L':
      name[i] = random_letter(mt);
      break;
    case 'N':
      name[i] = random_digit(mt);
      break;
    }
  }
  strncpy(buffer, name, buflen);
}


x86 assembly (clang, -O0):
<robot_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0x2ee2(%rip),%rsi
mov    $0x6,%edx
call   1070 <random_word@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1211 <robot_name+0xc1>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x44(%rbp)
sub    $0x4c,%eax
je     11d3 <robot_name+0x83>
jmp    11c2 <robot_name+0x72>
mov    -0x44(%rbp),%eax
sub    $0x4e,%eax
je     11eb <robot_name+0x9b>
jmp    11fe <robot_name+0xae>
mov    -0x8(%rbp),%rdi
call   1040 <random_letter@plt>
mov    %al,%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
jmp    11fe <robot_name+0xae>
mov    -0x8(%rbp),%rdi
call   1060 <random_digit@plt>
mov    %al,%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
jmp    1203 <robot_name+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <robot_name+0x43>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<robot_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x2ee4(%rip),%rsi
mov    $0x6,%edx
call   1070 <random_word@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     11cf <robot_name+0x7f>
xor    %ebp,%ebp
jmp    11b8 <robot_name+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1060 <random_digit@plt>
mov    %al,(%rsp,%rbp,1)
movzbl 0x1(%rbx,%rbp,1),%eax
add    $0x1,%rbp
test   %al,%al
je     11cf <robot_name+0x7f>
movsbl %al,%eax
cmp    $0x4e,%eax
je     11a0 <robot_name+0x50>
cmp    $0x4c,%eax
jne    11ab <robot_name+0x5b>
mov    %r12,%rdi
call   1040 <random_letter@plt>
jmp    11a8 <robot_name+0x58>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mtwist_state = type { i32 }
@robot_name.robot_patterns = internal global [6 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0)]
@.str = [5 x i8] c"LNLN\00"
@.str.1 = [5 x i8] c"LNLL\00"
@.str.2 = [5 x i8] c"LNNL\00"
@.str.3 = [5 x i8] c"LLNL\00"
@.str.4 = [5 x i8] c"LLNN\00"
@.str.5 = [5 x i8] c"LNNN\00"
define void @robot_name(%struct.mtwist_state* %0, i8* %1, i32 %2) {
%4 = alloca %struct.mtwist_state*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [20 x i8]
store %struct.mtwist_state* %0, %struct.mtwist_state** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load %struct.mtwist_state*, %struct.mtwist_state** %4
%11 = call i8* @random_word(%struct.mtwist_state* %10, i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @robot_name.robot_patterns, i64 0, i64 0), i32 6)
store i8* %11, i8** %7
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 20)
store i32 0, i32* %8
br label %14
14: ; preds = %41, %3
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %40 [
i32 76, label %28
i32 78, label %34
]
28: ; preds = %21
%29 = load %struct.mtwist_state*, %struct.mtwist_state** %4
%30 = call signext i8 @random_letter(%struct.mtwist_state* %29)
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 %32
store i8 %30, i8* %33
br label %40
34: ; preds = %21
%35 = load %struct.mtwist_state*, %struct.mtwist_state** %4
%36 = call signext i8 @random_digit(%struct.mtwist_state* %35)
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 %38
store i8 %36, i8* %39
br label %40
40: ; preds = %21, %34, %28
br label %41
41: ; preds = %40
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %14
44: ; preds = %14
%45 = load i8*, i8** %5
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* %6
%48 = call i32 @strncpy(i8* %45, i8* %46, i32 %47)
ret void
}

LLVM IR (-O2):
%struct.mtwist_state = type { i32 }
@robot_name.robot_patterns = internal global [6 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0)]
@.str = [5 x i8] c"LNLN\00"
@.str.1 = [5 x i8] c"LNLL\00"
@.str.2 = [5 x i8] c"LNNL\00"
@.str.3 = [5 x i8] c"LLNL\00"
@.str.4 = [5 x i8] c"LLNN\00"
@.str.5 = [5 x i8] c"LNNN\00"
define void @robot_name(%struct.mtwist_state* %0, i8* %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = tail call i8* @random_word(%struct.mtwist_state* %0, i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @robot_name.robot_patterns, i64 0, i64 0), i32 6)
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 20)
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %3, %21
%11 = phi i64 [ %22, %21 ], [ 0, %3 ]
%12 = phi i8 [ %24, %21 ], [ %8, %3 ]
%13 = sext i8 %12 to i32
switch i32 %13, label %21 [
i32 76, label %14
i32 78, label %16
]
14: ; preds = %10
%15 = call signext i8 @random_letter(%struct.mtwist_state* %0)
br label %18
16: ; preds = %10
%17 = call signext i8 @random_digit(%struct.mtwist_state* %0)
br label %18
18: ; preds = %16, %14
%19 = phi i8 [ %15, %14 ], [ %17, %16 ]
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %11
store i8 %19, i8* %20
br label %21
21: ; preds = %18, %10
%22 = add nuw i64 %11, 1
%23 = getelementptr inbounds i8, i8* %5, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %10
26: ; preds = %21, %3
%27 = call i32 @strncpy(i8* %1, i8* %6, i32 %2)
ret void
}