#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 */
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ getstr(char *, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
unsigned short GetUShort(const char *title, unsigned short deflt,
                         const char *help) {
  char s[80], sdeflt[80];
  int newval;
  while (1) {
    sprintf(s, "\n%s:%s", title, (*help) ? " (Type ? for Help)" : "");
    sprintf(sdeflt, "%d", deflt);
    getstr(s, sdeflt, s, sizeof(s));
    if (*s == '?' && *help)
      printf("%s", help);
    else {
      if (!sscanf(s, "%d", &newval))
        printf("unchanged (%d)\n", (newval = deflt));
      if (newval < 0)
        printf("Error: value must be >= zero\n");
      else
        return (newval);
    }
  }
}


x86 assembly (clang, -O0):
<GetUShort>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xebc(%rip),%rcx
lea    0xe90(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
movzwl -0xa(%rbp),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
lea    -0x70(%rbp),%rdx
mov    $0x50,%ecx
call   1040 <getstr@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x3f,%eax
jne    11f2 <GetUShort+0xb2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <GetUShort+0xb2>
mov    -0x18(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <GetUShort+0x121>
lea    -0x70(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    -0xc4(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x0,%eax
jne    122a <GetUShort+0xea>
movzwl -0xa(%rbp),%esi
mov    %esi,-0xc4(%rbp)
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc4(%rbp)
jge    124a <GetUShort+0x10a>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125c <GetUShort+0x11c>
mov    -0xc4(%rbp),%eax
movzwl %ax,%eax
add    $0xd0,%rsp
pop    %rbp
ret
jmp    1261 <GetUShort+0x121>
jmp    115a <GetUShort+0x1a>

x86 assembly (clang, -O2):
<GetUShort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x10(%rsp),%rbp
lea    0xea4(%rip),%r13
lea    0x60(%rsp),%r15
jmp    1196 <GetUShort+0x46>
nopl   (%rax)
cmpb   $0x0,(%rbx)
je     11e7 <GetUShort+0x97>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0x0,(%rbx)
lea    0xe8c(%rip),%rcx
je     11a9 <GetUShort+0x59>
lea    0xe5e(%rip),%rcx
mov    %rbp,%rdi
lea    0xe4d(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    $0x50,%ecx
call   1050 <getstr@plt>
cmpb   $0x3f,0x10(%rsp)
je     1180 <GetUShort+0x30>
mov    %rbp,%rdi
mov    %r13,%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
test   %eax,%eax
jne    1211 <GetUShort+0xc1>
mov    %r12d,0xc(%rsp)
lea    0xe16(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jns    122a <GetUShort+0xda>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
jmp    1196 <GetUShort+0x46>
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\0A%s:%s\00"
@.str.1 = [19 x i8] c" (Type ? for Help)\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [16 x i8] c"unchanged (%d)\0A\00"
@.str.6 = [30 x i8] c"Error: value must be >= zero\0A\00"
define zeroext i16 @GetUShort(i8* %0, i16 zeroext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca [80 x i8]
%8 = alloca [80 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
br label %10
10: ; preds = %3, %57
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %18)
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%21 = load i16, i16* %5
%22 = zext i16 %21 to i32
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%27 = call i32 @getstr(i8* %24, i8* %25, i8* %26, i32 80)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 63
br i1 %31, label %32, label %40
32: ; preds = %10
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %57
40: ; preds = %32, %10
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i16, i16* %5
%46 = zext i16 %45 to i32
store i32 %46, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %40
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %56
53: ; preds = %48
%54 = load i32, i32* %9
%55 = trunc i32 %54 to i16
ret i16 %55
56: ; preds = %51
br label %57
57: ; preds = %56, %37
br label %10
}

LLVM IR (-O2):
@.str = [7 x i8] c"\0A%s:%s\00"
@.str.1 = [19 x i8] c" (Type ? for Help)\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [16 x i8] c"unchanged (%d)\0A\00"
@str = [29 x i8] c"Error: value must be >= zero\00"
define zeroext i16 @GetUShort(i8* %0, i16 zeroext %1, i8* %2) {
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = bitcast i32* %6 to i8*
%10 = zext i16 %1 to i32
br label %11
11: ; preds = %35, %3
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0)
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %14)
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%17 = call i32 @getstr(i8* %7, i8* %8, i8* %7, i32 80)
%18 = load i8, i8* %7
%19 = icmp eq i8 %18, 63
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = load i8, i8* %2
%22 = icmp eq i8 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %35
25: ; preds = %20, %11
%26 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
store i32 %10, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %23
br label %11
36: ; preds = %30
%37 = trunc i32 %31 to i16
ret i16 %37
}