#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*/ scanf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned short);
int /*<<< orphan*/ sscanf(char *, char *, unsigned short *);
scalar_t__ strncasecmp(char *, char *, int);
unsigned short ReadPort(char port[16]) {
  unsigned short pn;
  scanf("%6s", port);
  if (strncasecmp(port, "COM", 3) == 0) {
    sscanf(port + 3, "%hu", &pn);
    snprintf(port, 16, "COM%hu", pn);
  } else if (strncasecmp(port, "USB", 3) == 0) {
    sscanf(port + 3, "%hu", &pn);
    snprintf(port, 16, "USB%hu", pn);
    pn += 32768;
  } else {
    sscanf(port, "%hu", &pn);
    snprintf(port, 16, "COM%hu", pn);
  }
  return pn;
}


x86 assembly (clang, -O0):
<ReadPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11b1 <ReadPort+0x71>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
lea    0xe8c(%rip),%rsi
lea    -0xa(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
lea    0xe65(%rip),%rdx
movzwl -0xa(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    1245 <ReadPort+0x105>
mov    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1213 <ReadPort+0xd3>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
lea    0xe37(%rip),%rsi
lea    -0xa(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
lea    0xe1b(%rip),%rdx
movzwl -0xa(%rbp),%ecx
call   1030 <snprintf@plt>
movzwl -0xa(%rbp),%eax
add    $0x8000,%eax
mov    %ax,-0xa(%rbp)
jmp    1240 <ReadPort+0x100>
mov    -0x8(%rbp),%rdi
lea    0xdf8(%rip),%rsi
lea    -0xa(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
lea    0xdd1(%rip),%rdx
movzwl -0xa(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    1245 <ReadPort+0x105>
movzwl -0xa(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadPort>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     119a <ReadPort+0x5a>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     11ca <ReadPort+0x8a>
lea    0xe86(%rip),%rsi
lea    0xe(%rsp),%rdx
mov    %rbx,%rdi
jmp    11aa <ReadPort+0x6a>
lea    0x3(%rbx),%rdi
lea    0xe71(%rip),%rsi
lea    0xe(%rsp),%rdx
call   1050 <sscanf@plt>
movzwl 0xe(%rsp),%ecx
lea    0xe4d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1030 <snprintf@plt>
jmp    11fd <ReadPort+0xbd>
lea    0x3(%rbx),%rdi
lea    0xe41(%rip),%rsi
lea    0xe(%rsp),%rdx
call   1050 <sscanf@plt>
movzwl 0xe(%rsp),%ecx
lea    0xe28(%rip),%rdx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1030 <snprintf@plt>
xorb   $0x80,0xf(%rsp)
movzwl 0xe(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%6s\00"
@.str.1 = [4 x i8] c"COM\00"
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [7 x i8] c"COM%hu\00"
@.str.4 = [4 x i8] c"USB\00"
@.str.5 = [7 x i8] c"USB%hu\00"
define zeroext i16 @ReadPort(i8* %0) {
%2 = alloca i8*
%3 = alloca i16
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 3
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%13 = load i8*, i8** %2
%14 = load i16, i16* %3
%15 = call i32 @snprintf(i8* %13, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %14)
br label %38
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i64 @strncasecmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%24 = load i8*, i8** %2
%25 = load i16, i16* %3
%26 = call i32 @snprintf(i8* %24, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i16 zeroext %25)
%27 = load i16, i16* %3
%28 = zext i16 %27 to i32
%29 = add nsw i32 %28, 32768
%30 = trunc i32 %29 to i16
store i16 %30, i16* %3
br label %37
31: ; preds = %16
%32 = load i8*, i8** %2
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%34 = load i8*, i8** %2
%35 = load i16, i16* %3
%36 = call i32 @snprintf(i8* %34, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %35)
br label %37
37: ; preds = %31, %20
br label %38
38: ; preds = %37, %9
%39 = load i16, i16* %3
ret i16 %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"%6s\00"
@.str.1 = [4 x i8] c"COM\00"
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [7 x i8] c"COM%hu\00"
@.str.4 = [4 x i8] c"USB\00"
@.str.5 = [7 x i8] c"USB%hu\00"
define zeroext i16 @ReadPort(i8* %0) {
%2 = alloca i16
%3 = bitcast i16* %2 to i8*
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 3
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%10 = load i16, i16* %2
%11 = call i32 @snprintf(i8* %0, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %10)
br label %26
12: ; preds = %1
%13 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 3
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%18 = load i16, i16* %2
%19 = call i32 @snprintf(i8* %0, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i16 zeroext %18)
%20 = load i16, i16* %2
%21 = xor i16 %20, -32768
store i16 %21, i16* %2
br label %26
22: ; preds = %12
%23 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%24 = load i16, i16* %2
%25 = call i32 @snprintf(i8* %0, i32 16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %24)
br label %26
26: ; preds = %15, %22, %7
%27 = load i16, i16* %2
ret i16 %27
}