#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 */
long abs(long);
int atoi(char *);
long atol(char *);
int /*<<< orphan*/ get_string(char *, int, char *, int);
void set_read_params(int cit_cmd, int *dir, int *rm_msg_nbr, long *searchkey) {
  int nbr;
  char nbr_str[12];
  switch (cit_cmd) {
  case 'B':
  case 'O':
  case 'R':
    *dir = (-1);
    *rm_msg_nbr = 200 - 1;
    break;
  case '#':
    *dir = 1;
    get_string("Find message by number -> ", 11, nbr_str, -1);
    *searchkey = atol(nbr_str);
    if (*searchkey < 0L)
      *searchkey = abs(*searchkey);
    *rm_msg_nbr = 0;
    break;
  case '-':
    *dir = 1;
    get_string("Read last how many msgs? -> ", 3, nbr_str, -1);
    nbr = atoi(nbr_str);
    if (nbr < 1)
      nbr = 0;
    if (nbr > (200 - 1))
      nbr = 200 - 1;
    *rm_msg_nbr = 200 - nbr;
    break;
  default:
    *dir = 1;
    *rm_msg_nbr = 0;
    break;
  }
  return;
}


x86 assembly (clang, -O0):
<set_read_params>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffdd,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x2f,%eax
ja     126b <set_read_params+0x12b>
mov    -0x38(%rbp),%rax
lea    0xe89(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xc7,(%rax)
jmp    127f <set_read_params+0x13f>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x30(%rbp),%rdx
lea    0xf12(%rip),%rdi
mov    $0xb,%esi
mov    $0xffffffff,%ecx
call   1040 <get_string@plt>
lea    -0x30(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jge    11f4 <set_read_params+0xb4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    127f <set_read_params+0x13f>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x30(%rbp),%rdx
lea    0xec3(%rip),%rdi
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1040 <get_string@plt>
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jge    1244 <set_read_params+0x104>
movl   $0x0,-0x24(%rbp)
cmpl   $0xc7,-0x24(%rbp)
jle    1258 <set_read_params+0x118>
movl   $0xc7,-0x24(%rbp)
mov    $0xc8,%ecx
sub    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    127f <set_read_params+0x13f>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_read_params>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
add    $0xffffffdd,%edi
cmp    $0x2f,%edi
ja     11a2 <set_read_params+0x72>
mov    %rcx,%rbx
lea    0xeb2(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movl   $0xffffffff,(%rsi)
mov    $0xc7,%eax
jmp    11f4 <set_read_params+0xc4>
movl   $0x1,(%rsi)
lea    0xf4c(%rip),%rdi
lea    0x4(%rsp),%r15
mov    $0xb,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1030 <get_string@plt>
mov    %r15,%rdi
call   1040 <atol@plt>
mov    %rax,%rcx
neg    %rcx
cmovs  %rax,%rcx
mov    %rcx,(%rbx)
jmp    11a8 <set_read_params+0x78>
movl   $0x1,(%rsi)
xor    %eax,%eax
jmp    11f4 <set_read_params+0xc4>
movl   $0x1,(%rsi)
lea    0xf22(%rip),%rdi
lea    0x4(%rsp),%rbx
mov    $0x3,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1030 <get_string@plt>
mov    %rbx,%rdi
call   1050 <atoi@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
cmp    $0xc7,%ecx
mov    $0xc7,%edx
cmovb  %ecx,%edx
mov    $0xc8,%eax
sub    %edx,%eax
mov    %eax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Find message by number -> \00"
@.str.1 = [29 x i8] c"Read last how many msgs? -> \00"
define void @set_read_params(i32 %0, i32* %1, i32* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64*
%9 = alloca i32
%10 = alloca [12 x i8]
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i64* %3, i64** %8
%11 = load i32, i32* %5
switch i32 %11, label %49 [
i32 66, label %12
i32 79, label %12
i32 82, label %12
i32 35, label %15
i32 45, label %32
]
12: ; preds = %4, %4, %4
%13 = load i32*, i32** %6
store i32 -1, i32* %13
%14 = load i32*, i32** %7
store i32 199, i32* %14
br label %52
15: ; preds = %4
%16 = load i32*, i32** %6
store i32 1, i32* %16
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%18 = call i32 @get_string(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 11, i8* %17, i32 -1)
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%20 = call i64 @atol(i8* %19)
%21 = load i64*, i64** %8
store i64 %20, i64* %21
%22 = load i64*, i64** %8
%23 = load i64, i64* %22
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = load i64*, i64** %8
%27 = load i64, i64* %26
%28 = call i64 @abs(i64 %27)
%29 = load i64*, i64** %8
store i64 %28, i64* %29
br label %30
30: ; preds = %25, %15
%31 = load i32*, i32** %7
store i32 0, i32* %31
br label %52
32: ; preds = %4
%33 = load i32*, i32** %6
store i32 1, i32* %33
%34 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%35 = call i32 @get_string(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %34, i32 -1)
%36 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 0, i32* %9
br label %41
41: ; preds = %40, %32
%42 = load i32, i32* %9
%43 = icmp sgt i32 %42, 199
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 199, i32* %9
br label %45
45: ; preds = %44, %41
%46 = load i32, i32* %9
%47 = sub nsw i32 200, %46
%48 = load i32*, i32** %7
store i32 %47, i32* %48
br label %52
49: ; preds = %4
%50 = load i32*, i32** %6
store i32 1, i32* %50
%51 = load i32*, i32** %7
store i32 0, i32* %51
br label %52
52: ; preds = %49, %45, %30, %12
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Find message by number -> \00"
@.str.1 = [29 x i8] c"Read last how many msgs? -> \00"
define void @set_read_params(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca [12 x i8]
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
switch i32 %0, label %20 [
i32 66, label %7
i32 79, label %7
i32 82, label %7
i32 35, label %8
i32 45, label %12
]
7: ; preds = %4, %4, %4
store i32 -1, i32* %1
br label %21
8: ; preds = %4
store i32 1, i32* %1
%9 = call i32 @get_string(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 11, i8* %6, i32 -1)
%10 = call i64 @atol(i8* %6)
%11 = call i64 @llvm.abs.i64(i64 %10, i1 true)
store i64 %11, i64* %3
br label %21
12: ; preds = %4
store i32 1, i32* %1
%13 = call i32 @get_string(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %6, i32 -1)
%14 = call i32 @atoi(i8* %6)
%15 = icmp sgt i32 %14, 0
%16 = select i1 %15, i32 %14, i32 0
%17 = icmp ult i32 %16, 199
%18 = select i1 %17, i32 %16, i32 199
%19 = sub nuw nsw i32 200, %18
br label %21
20: ; preds = %4
store i32 1, i32* %1
br label %21
21: ; preds = %20, %12, %8, %7
%22 = phi i32 [ 0, %20 ], [ %19, %12 ], [ 0, %8 ], [ 199, %7 ]
store i32 %22, i32* %2
ret void
}