#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, short);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, short *);
int main() {
  FILE *f = fopen("INP.TXT", "r");
  short x;
  fscanf(f, "%hd", &x);
  fclose(f);
  if (x > -2)
    x = -2;
  else
    do
      x--;
    while (x % 2);
  f = fopen("OUT.TXT", "w");
  fprintf(f, "%hd\n", x);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x12(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movswl -0x12(%rbp),%eax
cmp    $0xfffffffe,%eax
jle    119b <main+0x5b>
movw   $0xfffe,-0x12(%rbp)
jmp    11c6 <main+0x86>
jmp    11a0 <main+0x60>
mov    -0x12(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a0 <main+0x60>
jmp    11c6 <main+0x86>
lea    0xe41(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
movswl -0x12(%rbp),%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
lea    0xe(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movzwl 0xe(%rsp),%eax
mov    %eax,%ecx
or     $0xfffffffe,%ecx
add    %eax,%ecx
cmp    $0xffff,%ax
mov    $0xfffe,%eax
cmovl  %ecx,%eax
mov    %ax,0xe(%rsp)
lea    0xe73(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movswl 0xe(%rsp),%edx
lea    0xe62(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%hd\00"
@.str.3 = [8 x i8] c"OUT.TXT\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%hd\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i16
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%7 = load i32*, i32** %2
%8 = call i32 @fclose(i32* %7)
%9 = load i16, i16* %3
%10 = sext i16 %9 to i32
%11 = icmp sgt i32 %10, -2
br i1 %11, label %12, label %13
12: ; preds = %0
store i16 -2, i16* %3
br label %23
13: ; preds = %0
br label %14
14: ; preds = %17, %13
%15 = load i16, i16* %3
%16 = add i16 %15, -1
store i16 %16, i16* %3
br label %17
17: ; preds = %14
%18 = load i16, i16* %3
%19 = sext i16 %18 to i32
%20 = srem i32 %19, 2
%21 = icmp ne i32 %20, 0
br i1 %21, label %14, label %22
22: ; preds = %17
br label %23
23: ; preds = %22, %12
%24 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %2
%25 = load i32*, i32** %2
%26 = load i16, i16* %3
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i16 signext %26)
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%hd\00"
@.str.3 = [8 x i8] c"OUT.TXT\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%hd\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i16* %1 to i8*
%4 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %1)
%5 = call i32 @fclose(i32* %2)
%6 = load i16, i16* %1
%7 = icmp sgt i16 %6, -2
%8 = or i16 %6, -2
%9 = add i16 %8, %6
%10 = select i1 %7, i16 -2, i16 %9
store i16 %10, i16* %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = load i16, i16* %1
%13 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i16 signext %12)
%14 = call i32 @fclose(i32* %11)
ret i32 0
}