#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__ sscanf(char *, char *, short *);
scalar_t__ strlen(char *);
short ASCIIINT(char *S, short *Er) {
  short I;
  I = 0;
  if ((int)strlen(S) > 10) {
    *Er = 0;
    return I;
  }
  *Er = (sscanf(S, "%hd", &I) == 0);
  if (*Er == 0)
    *Er = 2;
  else
    *Er = 1;
  return I;
}


x86 assembly (clang, -O0):
<ASCIIINT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xa,%eax
jle    115e <ASCIIINT+0x3e>
mov    -0x18(%rbp),%rax
movw   $0x0,(%rax)
mov    -0x1a(%rbp),%ax
mov    %ax,-0x2(%rbp)
jmp    11b7 <ASCIIINT+0x97>
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
lea    -0x1a(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
movswl (%rax),%eax
cmp    $0x0,%eax
jne    11a6 <ASCIIINT+0x86>
mov    -0x18(%rbp),%rax
movw   $0x2,(%rax)
jmp    11af <ASCIIINT+0x8f>
mov    -0x18(%rbp),%rax
movw   $0x1,(%rax)
mov    -0x1a(%rbp),%ax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASCIIINT>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movw   $0x0,0x6(%rsp)
call   1030 <strlen@plt>
cmp    $0xa,%eax
jle    1141 <ASCIIINT+0x21>
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1166 <ASCIIINT+0x46>
lea    0xeb8(%rip),%rsi
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%rax
mov    $0x2,%cx
sbb    $0x0,%cx
movzwl 0x6(%rsp),%eax
mov    %cx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%hd\00"
define signext i16 @ASCIIINT(i8* %0, i16* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i16*
%6 = alloca i16
store i8* %0, i8** %4
store i16* %1, i16** %5
store i16 0, i16* %6
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
%10 = icmp sgt i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i16*, i16** %5
store i16 0, i16* %12
%13 = load i16, i16* %6
store i16 %13, i16* %3
br label %31
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %6)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = trunc i32 %18 to i16
%20 = load i16*, i16** %5
store i16 %19, i16* %20
%21 = load i16*, i16** %5
%22 = load i16, i16* %21
%23 = sext i16 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = load i16*, i16** %5
store i16 2, i16* %26
br label %29
27: ; preds = %14
%28 = load i16*, i16** %5
store i16 1, i16* %28
br label %29
29: ; preds = %27, %25
%30 = load i16, i16* %6
store i16 %30, i16* %3
br label %31
31: ; preds = %29, %11
%32 = load i16, i16* %3
ret i16 %32
}

LLVM IR (-O2):
@.str = [4 x i8] c"%hd\00"
define signext i16 @ASCIIINT(i8* %0, i16* nocapture writeonly %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 10
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %3)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i16 1, i16 2
%12 = load i16, i16* %3
br label %13
13: ; preds = %2, %8
%14 = phi i16 [ %12, %8 ], [ 0, %2 ]
%15 = phi i16 [ %11, %8 ], [ 0, %2 ]
store i16 %15, i16* %1
ret i16 %14
}