#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*/ Consoleprintf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char toupper(char);
scalar_t__ xindex(char *, char *);
int call_check_internal(char *callsign) {
  char call[20];
  int ssid;
  int err_flag = 0;
  int i;
  if (xindex(callsign, "-") > 0) {
    sscanf(callsign, "%[^-]-%d", call, &ssid);
    if (strlen(call) > 6) {
      Consoleprintf("Callsign too long, 6 characters before SSID");
      Consoleprintf("%s\r\n", callsign);
      err_flag = 1;
    }
    if (ssid < 0 || ssid > 15) {
      Consoleprintf("SSID out of range, must be between 0 and 15");
      Consoleprintf("%s\r\n", callsign);
      err_flag = 1;
    }
  } else {
    if (strlen(callsign) > 6) {
      Consoleprintf("Callsign too long, 6 characters maximum");
      Consoleprintf("%s\r\n", callsign);
      err_flag = 1;
    }
  }
  strcat(callsign, "          ");
  callsign[10] = '\0';
  for (i = 0; i < 10; i++)
    callsign[i] = toupper(callsign[i]);
  return (err_flag);
}


x86 assembly (clang, -O0):
<call_check_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <xindex@plt>
cmp    $0x0,%rax
jle    121e <call_check_internal+0xbe>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe66(%rip),%rsi
lea    -0x24(%rbp),%rcx
call   1070 <sscanf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
jle    11de <call_check_internal+0x7e>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
movl   $0x1,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11f2 <call_check_internal+0x92>
cmpl   $0xf,-0x24(%rbp)
jle    1219 <call_check_internal+0xb9>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    125c <call_check_internal+0xfc>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x6,%eax
jle    1257 <call_check_internal+0xf7>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <Consoleprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    125c <call_check_internal+0xfc>
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0xa(%rax)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    12b1 <call_check_internal+0x151>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127b <call_check_internal+0x11b>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_check_internal>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0xe90(%rip),%rsi
call   1060 <xindex@plt>
test   %rax,%rax
jle    11d9 <call_check_internal+0x79>
lea    0xe81(%rip),%rsi
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1070 <sscanf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x7,%eax
jl     11c9 <call_check_internal+0x69>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1050 <Consoleprintf@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <Consoleprintf@plt>
mov    $0x1,%ebp
cmpl   $0x10,0xc(%rsp)
jb     120c <call_check_internal+0xac>
lea    0xe65(%rip),%rdi
jmp    11ef <call_check_internal+0x8f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x7,%eax
jl     120c <call_check_internal+0xac>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <Consoleprintf@plt>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <Consoleprintf@plt>
mov    $0x1,%ebp
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
movb   $0x0,0xa(%rbx)
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x1(%rbx)
movsbl 0x2(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x2(%rbx)
movsbl 0x3(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x3(%rbx)
movsbl 0x4(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x4(%rbx)
movsbl 0x5(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x5(%rbx)
movsbl 0x6(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x6(%rbx)
movsbl 0x7(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x7(%rbx)
movsbl 0x8(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x8(%rbx)
movsbl 0x9(%rbx),%edi
call   1030 <toupper@plt>
mov    %al,0x9(%rbx)
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [9 x i8] c"%[^-]-%d\00"
@.str.2 = [44 x i8] c"Callsign too long, 6 characters before SSID\00"
@.str.3 = [5 x i8] c"%s\0D\0A\00"
@.str.4 = [44 x i8] c"SSID out of range, must be between 0 and 15\00"
@.str.5 = [40 x i8] c"Callsign too long, 6 characters maximum\00"
@.str.6 = [11 x i8] c" \00"
define i32 @call_check_internal(i8* %0) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = call i64 @xindex(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %32
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32* %4)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 6
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %19)
store i32 1, i32* %5
br label %21
21: ; preds = %17, %10
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 15
br i1 %26, label %27, label %31
27: ; preds = %24, %21
%28 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%29 = load i8*, i8** %2
%30 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %29)
store i32 1, i32* %5
br label %31
31: ; preds = %27, %24
br label %41
32: ; preds = %1
%33 = load i8*, i8** %2
%34 = call i32 @strlen(i8* %33)
%35 = icmp sgt i32 %34, 6
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%38 = load i8*, i8** %2
%39 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %38)
store i32 1, i32* %5
br label %40
40: ; preds = %36, %32
br label %41
41: ; preds = %40, %31
%42 = load i8*, i8** %2
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 10
store i8 0, i8* %45
store i32 0, i32* %6
br label %46
46: ; preds = %60, %41
%47 = load i32, i32* %6
%48 = icmp slt i32 %47, 10
br i1 %48, label %49, label %63
49: ; preds = %46
%50 = load i8*, i8** %2
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call signext i8 @toupper(i8 signext %54)
%56 = load i8*, i8** %2
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %49
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %46
63: ; preds = %46
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [9 x i8] c"%[^-]-%d\00"
@.str.2 = [44 x i8] c"Callsign too long, 6 characters before SSID\00"
@.str.3 = [5 x i8] c"%s\0D\0A\00"
@.str.4 = [44 x i8] c"SSID out of range, must be between 0 and 15\00"
@.str.5 = [40 x i8] c"Callsign too long, 6 characters maximum\00"
@.str.6 = [11 x i8] c" \00"
define i32 @call_check_internal(i8* %0) {
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i64 @xindex(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32* %3)
%10 = call i32 @strlen(i8* %4)
%11 = icmp sgt i32 %10, 6
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %12, %8
%16 = phi i32 [ 1, %12 ], [ 0, %8 ]
%17 = load i32, i32* %3
%18 = icmp ugt i32 %17, 15
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %28
22: ; preds = %1
%23 = tail call i32 @strlen(i8* %0)
%24 = icmp sgt i32 %23, 6
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @Consoleprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %22, %25, %19, %15
%29 = phi i32 [ 1, %19 ], [ %16, %15 ], [ 1, %25 ], [ 0, %22 ]
%30 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%31 = getelementptr inbounds i8, i8* %0, i64 10
store i8 0, i8* %31
%32 = load i8, i8* %0
%33 = call signext i8 @toupper(i8 signext %32)
store i8 %33, i8* %0
%34 = getelementptr inbounds i8, i8* %0, i64 1
%35 = load i8, i8* %34
%36 = call signext i8 @toupper(i8 signext %35)
store i8 %36, i8* %34
%37 = getelementptr inbounds i8, i8* %0, i64 2
%38 = load i8, i8* %37
%39 = call signext i8 @toupper(i8 signext %38)
store i8 %39, i8* %37
%40 = getelementptr inbounds i8, i8* %0, i64 3
%41 = load i8, i8* %40
%42 = call signext i8 @toupper(i8 signext %41)
store i8 %42, i8* %40
%43 = getelementptr inbounds i8, i8* %0, i64 4
%44 = load i8, i8* %43
%45 = call signext i8 @toupper(i8 signext %44)
store i8 %45, i8* %43
%46 = getelementptr inbounds i8, i8* %0, i64 5
%47 = load i8, i8* %46
%48 = call signext i8 @toupper(i8 signext %47)
store i8 %48, i8* %46
%49 = getelementptr inbounds i8, i8* %0, i64 6
%50 = load i8, i8* %49
%51 = call signext i8 @toupper(i8 signext %50)
store i8 %51, i8* %49
%52 = getelementptr inbounds i8, i8* %0, i64 7
%53 = load i8, i8* %52
%54 = call signext i8 @toupper(i8 signext %53)
store i8 %54, i8* %52
%55 = getelementptr inbounds i8, i8* %0, i64 8
%56 = load i8, i8* %55
%57 = call signext i8 @toupper(i8 signext %56)
store i8 %57, i8* %55
%58 = getelementptr inbounds i8, i8* %0, i64 9
%59 = load i8, i8* %58
%60 = call signext i8 @toupper(i8 signext %59)
store i8 %60, i8* %58
ret i32 %29
}