#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 */
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ get_representation(unsigned short);
int /*<<< orphan*/ print_representation(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, unsigned short *);
int main() {
  unsigned short val;
  while (1) {
    errno = 0;
    printf("Enter a number: ");
    if (scanf("%hu", &val) != 1)
      break;
    if (errno == ERANGE) {
      printf("Value is too large, max. allowed is %d\n", 65535);
      continue;
    }
    printf("\nSeven-segment representation:\n");
    print_representation(get_representation(val), 5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
movq   $0x0,(%rax)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    -0x6(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1189 <main+0x49>
jmp    11e3 <main+0xa3>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11bb <main+0x7b>
lea    0xe6b(%rip),%rdi
mov    $0xffff,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114f <main+0xf>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzwl -0x6(%rbp),%edi
call   1030 <get_representation@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   1060 <print_representation@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e76(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    121e <main+0xce>
mov    0x2e4f(%rip),%r14
lea    0xe60(%rip),%r15
lea    0xe6a(%rip),%r12
lea    0x6(%rsp),%rbx
lea    0xe8a(%rip),%r13
jmp    11f5 <main+0xa5>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe4e(%rip),%rdi
mov    $0xffff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movq   $0x0,0x0(%rbp)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    121e <main+0xce>
mov    0x0(%rbp),%rax
cmp    (%r14),%rax
je     11c0 <main+0x70>
mov    %r13,%rdi
call   1030 <puts@plt>
movzwl 0x6(%rsp),%edi
call   1040 <get_representation@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   1070 <print_representation@plt>
jmp    11d3 <main+0x83>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [4 x i8] c"%hu\00"
@ERANGE = global i64 0
@.str.2 = [40 x i8] c"Value is too large, max. allowed is %d\0A\00"
@.str.3 = [32 x i8] c"\0ASeven-segment representation:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
store i32 0, i32* %1
br label %3
3: ; preds = %0, %12, %14
store i64 0, i64* @errno
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %2)
%6 = icmp ne i32 %5, 1
br i1 %6, label %7, label %8
7: ; preds = %3
br label %19
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @ERANGE
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 65535)
br label %3
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%16 = load i16, i16* %2
%17 = call i32 @get_representation(i16 zeroext %16)
%18 = call i32 @print_representation(i32 %17, i32 5)
br label %3
19: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [4 x i8] c"%hu\00"
@ERANGE = global i64 0
@.str.2 = [40 x i8] c"Value is too large, max. allowed is %d\0A\00"
@str = [31 x i8] c"\0ASeven-segment representation:\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
store i64 0, i64* @errno
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %21
6: ; preds = %0, %12
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 65535)
br label %12
12: ; preds = %10, %16
store i64 0, i64* @errno
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %6, label %21
16: ; preds = %6
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%18 = load i16, i16* %1
%19 = call i32 @get_representation(i16 zeroext %18)
%20 = call i32 @print_representation(i32 %19, i32 5)
br label %12
21: ; preds = %12, %0
ret i32 0
}