#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 */
char *getenv(char *);
long strtol(char const *, char **, int);
int get_testcase(void) {
  const char *s;
  char *eptr;
  long testcase_number;
  if ((s = getenv("SMSL_TESTCASE")) == NULL) {
    return 0;
  }
  testcase_number = strtol(s, &eptr, 10);
  if ((eptr == NULL) || (*eptr != '\0') || (testcase_number < 0) ||
      (testcase_number > 8)) {
    return -1;
  }
  return testcase_number;
}


x86 assembly (clang, -O0):
<get_testcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    114e <get_testcase+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <get_testcase+0x88>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1195 <get_testcase+0x75>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1195 <get_testcase+0x75>
cmpq   $0x0,-0x20(%rbp)
jl     1195 <get_testcase+0x75>
cmpq   $0x8,-0x20(%rbp)
jle    11a1 <get_testcase+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <get_testcase+0x88>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_testcase>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1169 <get_testcase+0x49>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     116d <get_testcase+0x4d>
cmp    $0x9,%rax
mov    $0xffffffff,%edx
mov    %eax,%esi
cmovge %edx,%esi
test   %rax,%rax
cmovs  %edx,%esi
xor    %eax,%eax
cmp    (%rcx),%al
sbb    %eax,%eax
or     %esi,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"SMSL_TESTCASE\00"
define i32 @get_testcase() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = call i64 @strtol(i8* %3, i8** %1, i32 10)
%7 = load i8*, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = load i8, i8* %7
%11 = icmp ne i8 %10, 0
%12 = icmp slt i64 %6, 0
%13 = select i1 %11, i1 true, i1 %12
%14 = icmp sgt i64 %6, 8
%15 = select i1 %13, i1 true, i1 %14
%16 = trunc i64 %6 to i32
%17 = select i1 %15, i32 -1, i32 %16
br label %18
18: ; preds = %9, %5, %0
%19 = phi i32 [ 0, %0 ], [ -1, %5 ], [ %17, %9 ]
ret i32 %19
}