#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int optind;
int /*<<< orphan*/ printf(char *, char *);
char *r40_to_ascii(int *, int, int /*<<< orphan*/ *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int decode(int argc, char **argv, int indx) {
  int i = 0;
  uint16_t buf[64 * 1024];
  char *out;
  int val;
  int res;
  while (optind < argc) {
    res = sscanf(argv[optind], "%i", &val);
    if ((val < 0) || (val > 0xffff) || (res != 1)) {
      fprintf(stderr, "Value '%s' is not a 16-bit integer\n", argv[optind]);
      return 1;
    }
    buf[i] = val & 0xffff;
    optind++;
    i++;
  }
  out = r40_to_ascii(buf, i, NULL);
  printf("%s\n", out);
  free(out);
  return 0;
}


x86 assembly (clang, -O0):
<decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40030,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1240 <decode+0xf0>
mov    -0x10(%rbp),%rax
mov    0x2e5f(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe69(%rip),%rsi
lea    -0x4002c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,-0x40030(%rbp)
cmpl   $0x0,-0x4002c(%rbp)
jl     11d3 <decode+0x83>
cmpl   $0xffff,-0x4002c(%rbp)
jg     11d3 <decode+0x83>
cmpl   $0x1,-0x40030(%rbp)
je     1206 <decode+0xb6>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2e01(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <decode+0x130>
mov    -0x4002c(%rbp),%ecx
and    $0xffff,%ecx
movslq -0x18(%rbp),%rax
mov    %ecx,-0x40020(%rbp,%rax,4)
mov    0x2dc4(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2db8(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <decode+0x1c>
lea    -0x40020(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <r40_to_ascii@plt>
mov    %rax,-0x40028(%rbp)
mov    -0x40028(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x40028(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40018,%rsp
mov    0x2e80(%rip),%r14
mov    (%r14),%eax
xor    %r12d,%r12d
mov    $0x0,%ebx
cmp    %edi,%eax
jge    11c9 <decode+0x79>
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xe7b(%rip),%r12
lea    0xc(%rsp),%r13
nopw   0x0(%rax,%rax,1)
cltq
mov    (%r15,%rax,8),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11f3 <decode+0xa3>
mov    0xc(%rsp),%eax
cmp    $0x10000,%eax
jae    11f3 <decode+0xa3>
mov    %eax,0x10(%rsp,%rbx,4)
mov    (%r14),%eax
add    $0x1,%eax
mov    %eax,(%r14)
add    $0x1,%rbx
cmp    %ebp,%eax
jl     1190 <decode+0x40>
xor    %r12d,%r12d
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1040 <r40_to_ascii@plt>
mov    %rax,%rbx
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1215 <decode+0xc5>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
movslq (%r14),%rax
mov    (%r15,%rax,8),%rdx
lea    0xdf9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x40018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@optind = global i32 0
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Value '%s' is not a 16-bit integer\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @decode(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca [65536 x i32]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %40, %3
%14 = load i32, i32* @optind
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %50
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i32, i32* @optind
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
store i32 %23, i32* %12
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %17
%27 = load i32, i32* %11
%28 = icmp sgt i32 %27, 65535
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %12
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %40
32: ; preds = %29, %26, %17
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %6
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %38)
store i32 1, i32* %4
br label %58
40: ; preds = %29
%41 = load i32, i32* %11
%42 = and i32 %41, 65535
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [65536 x i32], [65536 x i32]* %9, i64 0, i64 %44
store i32 %42, i32* %45
%46 = load i32, i32* @optind
%47 = add nsw i32 %46, 1
store i32 %47, i32* @optind
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %13
50: ; preds = %13
%51 = getelementptr inbounds [65536 x i32], [65536 x i32]* %9, i64 0, i64 0
%52 = load i32, i32* %8
%53 = call i8* @r40_to_ascii(i32* %51, i32 %52, i32* null)
store i8* %53, i8** %10
%54 = load i8*, i8** %10
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = load i8*, i8** %10
%57 = call i32 @free(i8* %56)
store i32 0, i32* %4
br label %58
58: ; preds = %50, %32
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@optind = global i32 0
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Value '%s' is not a 16-bit integer\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @decode(i32 %0, i8** nocapture %1, i32 %2) {
%4 = alloca [65536 x i32]
%5 = alloca i32
%6 = bitcast [65536 x i32]* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* @optind
%9 = icmp slt i32 %8, %0
br i1 %9, label %10, label %36
10: ; preds = %3, %28
%11 = phi i64 [ %32, %28 ], [ 0, %3 ]
%12 = phi i32 [ %31, %28 ], [ %8, %3 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %5
%18 = icmp ugt i32 %17, 65535
%19 = icmp ne i32 %16, 1
%20 = or i1 %19, %18
br i1 %20, label %21, label %28
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = load i32, i32* @optind
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %42
28: ; preds = %10
%29 = getelementptr inbounds [65536 x i32], [65536 x i32]* %4, i64 0, i64 %11
store i32 %17, i32* %29
%30 = load i32, i32* @optind
%31 = add nsw i32 %30, 1
store i32 %31, i32* @optind
%32 = add nuw i64 %11, 1
%33 = icmp slt i32 %31, %0
br i1 %33, label %10, label %34
34: ; preds = %28
%35 = trunc i64 %32 to i32
br label %36
36: ; preds = %34, %3
%37 = phi i32 [ 0, %3 ], [ %35, %34 ]
%38 = getelementptr inbounds [65536 x i32], [65536 x i32]* %4, i64 0, i64 0
%39 = call i8* @r40_to_ascii(i32* %38, i32 %37, i32* null)
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = call i32 @free(i8* %39)
br label %42
42: ; preds = %36, %21
%43 = phi i32 [ 1, %21 ], [ 0, %36 ]
ret i32 %43
}