#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char toupper(char);
int sanitisecommandname(const char *cmdname, char *cmdbuf) {
  int len, i;
  strncpy(cmdbuf, cmdname, 100);
  cmdbuf[100 - 1] = '\0';
  len = strlen(cmdbuf);
  for (i = 0; i < len; i++) {
    cmdbuf[i] = toupper(cmdbuf[i]);
    if (cmdbuf[i] < 'A' || cmdbuf[i] > 'Z') {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sanitisecommandname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x63(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e0 <sanitisecommandname+0xb0>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x41,%eax
jl     11c1 <sanitisecommandname+0x91>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5a,%eax
jle    11cd <sanitisecommandname+0x9d>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <sanitisecommandname+0xb7>
jmp    11d2 <sanitisecommandname+0xa2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116d <sanitisecommandname+0x3d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitisecommandname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rsi
mov    %r15,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x63(%r15)
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    117d <sanitisecommandname+0x4d>
mov    %eax,%r14d
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %al,(%r15,%rbx,1)
add    $0xa5,%al
cmp    $0xe5,%al
jbe    1181 <sanitisecommandname+0x51>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <sanitisecommandname+0x30>
xor    %eax,%eax
jmp    1186 <sanitisecommandname+0x56>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sanitisecommandname(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 100)
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 99
store i8 0, i8* %12
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %6
store i32 0, i32* %7
br label %15
15: ; preds = %47, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %50
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call signext i8 @toupper(i8 signext %24)
%26 = load i8*, i8** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp slt i32 %35, 65
br i1 %36, label %45, label %37
37: ; preds = %19
%38 = load i8*, i8** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp sgt i32 %43, 90
br i1 %44, label %45, label %46
45: ; preds = %37, %19
store i32 1, i32* %3
br label %51
46: ; preds = %37
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %15
50: ; preds = %15
store i32 0, i32* %3
br label %51
51: ; preds = %50, %45
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @sanitisecommandname(i8* %0, i8* %1) {
%3 = tail call i32 @strncpy(i8* %1, i8* %0, i32 100)
%4 = getelementptr inbounds i8, i8* %1, i64 99
store i8 0, i8* %4
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = zext i32 %5 to i64
br label %11
9: ; preds = %11
%10 = icmp eq i64 %18, %8
br i1 %10, label %19, label %11
11: ; preds = %7, %9
%12 = phi i64 [ 0, %7 ], [ %18, %9 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = tail call signext i8 @toupper(i8 signext %14)
store i8 %15, i8* %13
%16 = add i8 %15, -91
%17 = icmp ult i8 %16, -26
%18 = add nuw nsw i64 %12, 1
br i1 %17, label %19, label %9
19: ; preds = %11, %9, %2
%20 = phi i32 [ 0, %2 ], [ 0, %9 ], [ 1, %11 ]
ret i32 %20
}