#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 rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int rand_pos(int max) {
  int b;
  srand((unsigned int)(time(NULL) + (rand() % 100)));
  b = (rand() % max) + 1;
  while (b == max || b == max - 1 || b == 0)
    b = (rand() % max) + 1;
  return b;
}


x86 assembly (clang, -O0):
<rand_pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq %edx,%rcx
add    %rcx,%rax
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x4(%rbp)
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%al
cmp    -0x4(%rbp),%ecx
mov    %al,-0x11(%rbp)
je     11aa <rand_pos+0x7a>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
je     11aa <rand_pos+0x7a>
cmpl   $0x0,-0x8(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11ba <rand_pos+0x8a>
jmp    11d0 <rand_pos+0xa0>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x4(%rbp)
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
jmp    1179 <rand_pos+0x49>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_pos>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
add    %eax,%r14d
mov    %r14d,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
lea    -0x1(%rbx),%ebp
jmp    1187 <rand_pos+0x57>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebx
add    $0x1,%edx
cmp    %ebx,%edx
je     1180 <rand_pos+0x50>
cmp    %ebp,%edx
je     1180 <rand_pos+0x50>
test   %edx,%edx
je     1180 <rand_pos+0x50>
mov    %edx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rand_pos(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i64 @time(i32* null)
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 100
%7 = sext i32 %6 to i64
%8 = add nsw i64 %4, %7
%9 = trunc i64 %8 to i32
%10 = call i32 @srand(i32 %9)
%11 = call i32 (...) @rand()
%12 = load i32, i32* %2
%13 = srem i32 %11, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %15
15: ; preds = %29, %1
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp eq i32 %16, %17
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = sub nsw i32 %21, 1
%23 = icmp eq i32 %20, %22
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 0
br label %27
27: ; preds = %24, %19, %15
%28 = phi i1 [ true, %19 ], [ true, %15 ], [ %26, %24 ]
br i1 %28, label %29, label %34
29: ; preds = %27
%30 = call i32 (...) @rand()
%31 = load i32, i32* %2
%32 = srem i32 %30, %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %15
34: ; preds = %27
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @rand_pos(i32 %0) {
%2 = tail call i64 @time(i32* null)
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 100
%5 = trunc i64 %2 to i32
%6 = add i32 %4, %5
%7 = tail call i32 @srand(i32 %6)
%8 = tail call i32 (...) @rand()
%9 = add nsw i32 %0, -1
br label %10
10: ; preds = %19, %1
%11 = phi i32 [ %8, %1 ], [ %20, %19 ]
%12 = srem i32 %11, %0
%13 = add nsw i32 %12, 1
%14 = icmp eq i32 %13, %0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = icmp eq i32 %13, %9
%17 = icmp eq i32 %13, 0
%18 = or i1 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %10, %15
%20 = tail call i32 (...) @rand()
br label %10
21: ; preds = %15
ret i32 %13
}