#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
void set_DecScale(unsigned char *pds, int dec_scale) {
  if (dec_scale >= 0 && dec_scale < 32768) {
    pds[26] = ((unsigned int)dec_scale) >> 8;
    pds[27] = dec_scale & 255;
  } else if (dec_scale < 0 && dec_scale > -32768) {
    dec_scale = -dec_scale;
    pds[26] = (((unsigned int)dec_scale) >> 8) | 128;
    pds[27] = dec_scale & 255;
  } else {
    fprintf(stderr, "Bad dec_scale %d\n", dec_scale);
    exit(8);
  }
}


x86 assembly (clang, -O0):
<set_DecScale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     116b <set_DecScale+0x4b>
cmpl   $0x8000,-0xc(%rbp)
jge    116b <set_DecScale+0x4b>
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1a(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1b(%rax)
jmp    11db <set_DecScale+0xbb>
cmpl   $0x0,-0xc(%rbp)
jge    11b4 <set_DecScale+0x94>
cmpl   $0xffff8000,-0xc(%rbp)
jle    11b4 <set_DecScale+0x94>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1a(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1b(%rax)
jmp    11d6 <set_DecScale+0xb6>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe39(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x8,%edi
call   1040 <exit@plt>
jmp    11db <set_DecScale+0xbb>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_DecScale>:
push   %rax
mov    %esi,%edx
cmp    $0x7fff,%esi
ja     1132 <set_DecScale+0x12>
mov    %edx,%eax
shr    $0x8,%eax
jmp    1143 <set_DecScale+0x23>
cmp    $0xffff8001,%edx
jb     114b <set_DecScale+0x2b>
neg    %edx
mov    %edx,%eax
shr    $0x8,%eax
or     $0x80,%al
mov    %al,0x1a(%rdi)
mov    %dl,0x1b(%rdi)
pop    %rax
ret
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x8,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Bad dec_scale %d\0A\00"
define void @set_DecScale(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 32768
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load i32, i32* %4
%12 = lshr i32 %11, 8
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 26
store i8 %13, i8* %15
%16 = load i32, i32* %4
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 27
store i8 %18, i8* %20
br label %47
21: ; preds = %7, %2
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, -32768
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32, i32* %4
%29 = sub nsw i32 0, %28
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = lshr i32 %30, 8
%32 = or i32 %31, 128
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 26
store i8 %33, i8* %35
%36 = load i32, i32* %4
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 27
store i8 %38, i8* %40
br label %46
41: ; preds = %24, %21
%42 = load i32, i32* @stderr
%43 = load i32, i32* %4
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = call i32 @exit(i32 8)
unreachable
46: ; preds = %27
br label %47
47: ; preds = %46, %10
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Bad dec_scale %d\0A\00"
define void @set_DecScale(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp ult i32 %1, 32768
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = lshr i32 %1, 8
%6 = trunc i32 %5 to i8
br label %18
7: ; preds = %2
%8 = icmp ugt i32 %1, -32768
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = sub nsw i32 0, %1
%11 = lshr i32 %10, 8
%12 = trunc i32 %11 to i8
%13 = or i8 %12, -128
br label %18
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %1)
%17 = tail call i32 @exit(i32 8)
unreachable
18: ; preds = %9, %4
%19 = phi i8 [ %13, %9 ], [ %6, %4 ]
%20 = phi i32 [ %10, %9 ], [ %1, %4 ]
%21 = getelementptr inbounds i8, i8* %0, i64 26
store i8 %19, i8* %21
%22 = trunc i32 %20 to i8
%23 = getelementptr inbounds i8, i8* %0, i64 27
store i8 %22, i8* %23
ret void
}