#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_seed();
int getopt(int, char **, char *);
size_t optind;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, long);
long rand_range(long, long);
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int opt;
  long min = 0, max = 0;
  long rval = 0;
  char *end;
  while ((opt = getopt(argc, argv, ":h")) != -1) {
    switch (opt) {
    case 'h':
      print_help();
      return 0;
    default:
      print_help();
      return 1;
    }
  }
  if (argc != 2 && argc != 3) {
    print_help();
    return 1;
  }
  max = strtol(argv[1], &end, 10);
  if (argv[1][0] == '\0' || *end != '\0') {
    fprintf(stderr, "ERROR: Invalid range value1 '%s'\n\n", argv[optind]);
    print_help();
    return 1;
  }
  if (argc == 3) {
    min = strtol(argv[2], &end, 10);
    if (argv[2][0] == '\0' || *end != '\0') {
      fprintf(stderr, "ERROR: Invalid range value2 '%s'\n\n", argv[optind + 1]);
      print_help();
      return 1;
    }
  }
  srandom(get_seed());
  rval = (min > max) ? rand_range(max, min) : rand_range(min, max);
  printf("%ld\n", rval);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1204 <main+0x84>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
jne    11f1 <main+0x71>
jmp    11de <main+0x5e>
mov    $0x0,%al
call   1090 <print_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    138d <main+0x20d>
mov    $0x0,%al
call   1090 <print_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    138d <main+0x20d>
cmpl   $0x2,-0x8(%rbp)
je     122b <main+0xab>
cmpl   $0x3,-0x8(%rbp)
je     122b <main+0xab>
mov    $0x0,%al
call   1090 <print_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    138d <main+0x20d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1269 <main+0xe9>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a3 <main+0x123>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2d6b(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd78(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1090 <print_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    138d <main+0x20d>
cmpl   $0x3,-0x8(%rbp)
jne    132b <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12eb <main+0x16b>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1326 <main+0x1a6>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2ce9(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rdx
lea    0xd18(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1090 <print_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    138d <main+0x20d>
jmp    132b <main+0x1ab>
mov    $0x0,%al
call   1070 <get_seed@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    135d <main+0x1dd>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <rand_range@plt>
mov    %rax,-0x40(%rbp)
jmp    136e <main+0x1ee>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <rand_range@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xcc8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe6c(%rip),%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x2e>
cmp    $0x68,%eax
jne    1204 <main+0x84>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <print_help@plt>
jmp    1210 <main+0x90>
mov    %ebp,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1204 <main+0x84>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rax
cmpb   $0x0,(%rax)
je     11e1 <main+0x61>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     121b <main+0x9b>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rdx
lea    0xe04(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1090 <print_help@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x3,%ebp
jne    126a <main+0xea>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbp
mov    0x10(%rbx),%rax
cmpb   $0x0,(%rax)
je     1249 <main+0xc9>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     126c <main+0xec>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%rax
mov    0x8(%rbx,%rax,8),%rdx
lea    0xdbe(%rip),%rsi
jmp    11ff <main+0x7f>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <get_seed@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
cmp    %r14,%rbp
jle    1287 <main+0x107>
mov    %r14,%rdi
mov    %rbp,%rsi
jmp    128d <main+0x10d>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <rand_range@plt>
lea    0xdb0(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %ebx,%ebx
jmp    1210 <main+0x90>

LLVM IR (-O0):
@.str = [3 x i8] c":h\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ERROR: Invalid range value1 '%s'\0A\0A\00"
@optind = global i64 0
@.str.2 = [35 x i8] c"ERROR: Invalid range value2 '%s'\0A\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
br label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %20 [
i32 104, label %18
]
18: ; preds = %16
%19 = call i32 (...) @print_help()
store i32 0, i32* %3
br label %103
20: ; preds = %16
%21 = call i32 (...) @print_help()
store i32 1, i32* %3
br label %103
22: ; preds = %11
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (...) @print_help()
store i32 1, i32* %3
br label %103
30: ; preds = %25, %22
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @strtol(i8* %33, i8** %10, i32 10)
store i64 %34, i64* %8
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %30
%43 = load i8*, i8** %10
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %42, %30
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = load i64, i64* @optind
%51 = getelementptr inbounds i8*, i8** %49, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 (...) @print_help()
store i32 1, i32* %3
br label %103
55: ; preds = %42
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 3
br i1 %57, label %58, label %85
58: ; preds = %55
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i64 @strtol(i8* %61, i8** %10, i32 10)
store i64 %62, i64* %7
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 0
br i1 %69, label %75, label %70
70: ; preds = %58
%71 = load i8*, i8** %10
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %84
75: ; preds = %70, %58
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = load i64, i64* @optind
%79 = add i64 %78, 1
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %81)
%83 = call i32 (...) @print_help()
store i32 1, i32* %3
br label %103
84: ; preds = %70
br label %85
85: ; preds = %84, %55
%86 = call i32 (...) @get_seed()
%87 = call i32 @srandom(i32 %86)
%88 = load i64, i64* %7
%89 = load i64, i64* %8
%90 = icmp sgt i64 %88, %89
br i1 %90, label %91, label %95
91: ; preds = %85
%92 = load i64, i64* %8
%93 = load i64, i64* %7
%94 = call i64 @rand_range(i64 %92, i64 %93)
br label %99
95: ; preds = %85
%96 = load i64, i64* %7
%97 = load i64, i64* %8
%98 = call i64 @rand_range(i64 %96, i64 %97)
br label %99
99: ; preds = %95, %91
%100 = phi i64 [ %94, %91 ], [ %98, %95 ]
store i64 %100, i64* %9
%101 = load i64, i64* %9
%102 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %101)
store i32 0, i32* %3
br label %103
103: ; preds = %99, %75, %47, %28, %20, %18
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@.str = [3 x i8] c":h\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ERROR: Invalid range value1 '%s'\0A\0A\00"
@optind = global i64 0
@.str.2 = [35 x i8] c"ERROR: Invalid range value2 '%s'\0A\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %8 [
i32 -1, label %10
i32 104, label %6
]
6: ; preds = %2
%7 = tail call i32 (...) @print_help()
br label %66
8: ; preds = %2
%9 = tail call i32 (...) @print_help()
br label %66
10: ; preds = %2
%11 = and i32 %0, -2
%12 = icmp eq i32 %11, 2
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (...) @print_help()
br label %66
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strtol(i8* %17, i8** %3, i32 10)
%19 = load i8*, i8** %16
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %22, %15
%27 = load i32, i32* @stderr
%28 = load i64, i64* @optind
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = tail call i32 (...) @print_help()
br label %66
33: ; preds = %22
%34 = icmp eq i32 %0, 3
br i1 %34, label %35, label %54
35: ; preds = %33
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = load i8*, i8** %36
%38 = call i64 @strtol(i8* %37, i8** %3, i32 10)
%39 = load i8*, i8** %36
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %54, label %46
46: ; preds = %42, %35
%47 = load i32, i32* @stderr
%48 = load i64, i64* @optind
%49 = add i64 %48, 1
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = load i8*, i8** %50
%52 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = tail call i32 (...) @print_help()
br label %66
54: ; preds = %42, %33
%55 = phi i64 [ %38, %42 ], [ 0, %33 ]
%56 = tail call i32 (...) @get_seed()
%57 = tail call i32 @srandom(i32 %56)
%58 = icmp sgt i64 %55, %18
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = tail call i64 @rand_range(i64 %18, i64 %55)
br label %63
61: ; preds = %54
%62 = tail call i64 @rand_range(i64 %55, i64 %18)
br label %63
63: ; preds = %61, %59
%64 = phi i64 [ %60, %59 ], [ %62, %61 ]
%65 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %64)
br label %66
66: ; preds = %63, %46, %26, %13, %8, %6
%67 = phi i32 [ 0, %6 ], [ 1, %8 ], [ 1, %13 ], [ 1, %26 ], [ 1, %46 ], [ 0, %63 ]
ret i32 %67
}