#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int atoi(char *);
int *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int max;
  int nvals;
  int val;
  int sofar;
  int *already;
  if (argc < 4) {
    fprintf(stderr, "Usage: %s max nvals seed\n", argv[0]);
    return EXIT_FAILURE;
  }
  max = atoi(argv[1]);
  nvals = atoi(argv[2]);
  if (nvals > max / 3) {
    fprintf(stderr, "%s: nvals << max\n", argv[0]);
    return EXIT_FAILURE;
  }
  if (nvals > 1000) {
    fprintf(stderr, "%s: nvals <= 1000\n", argv[0]);
    return EXIT_FAILURE;
  }
  srand(atoi(argv[3]));
  already = calloc(nvals, sizeof(int));
  assert(already != NULL);
  sofar = 0;
  while (sofar < nvals) {
    val = 1 + (rand() % max);
    if (!already[val]) {
      printf("%d\n", val);
      already[val] = 1;
      sofar++;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11bd <main+0x4d>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x197>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    1228 <main+0xb8>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x197>
cmpl   $0x3e8,-0x18(%rbp)
jle    1262 <main+0xf2>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde0(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x197>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x18(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12fb <main+0x18b>
mov    $0x0,%al
call   1090 <rand@plt>
cltd
idivl  -0x14(%rbp)
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    12f6 <main+0x186>
mov    -0x1c(%rbp),%esi
lea    0xd66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12a0 <main+0x130>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jge    118c <main+0x1c>
lea    0xe76(%rip),%rsi
jmp    11d9 <main+0x69>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
movslq %r14d,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
cmp    %eax,%r12d
jle    11c9 <main+0x59>
lea    0xe53(%rip),%rsi
jmp    11d9 <main+0x69>
cmp    $0x3e8,%r12d
jle    1204 <main+0x94>
lea    0xe53(%rip),%rsi
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
call   1070 <fprintf@plt>
mov    0x2de7(%rip),%r13
mov    0x0(%r13),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    %r12d,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    0x2d97(%rip),%r13
test   %r12d,%r12d
jle    11f1 <main+0x81>
xor    %r15d,%r15d
jmp    1255 <main+0xe5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r12d,%r15d
jge    11f1 <main+0x81>
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %r14d
movslq %edx,%rbp
cmpl   $0x0,0x4(%rbx,%rbp,4)
jne    1250 <main+0xe0>
add    $0x1,%rbp
lea    0xdca(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movl   $0x1,(%rbx,%rbp,4)
add    $0x1,%r15d
jmp    1250 <main+0xe0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s max nvals seed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%s: nvals << max\0A\00"
@.str.2 = [19 x i8] c"%s: nvals <= 1000\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %89
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = sdiv i32 %30, 3
%32 = icmp sgt i32 %29, %31
br i1 %32, label %33, label %40
33: ; preds = %20
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %89
40: ; preds = %20
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 1000
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %3
br label %89
50: ; preds = %40
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 3
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
%55 = call i32 @srand(i32 %54)
%56 = load i32, i32* %7
%57 = call i32* @calloc(i32 %56, i32 4)
store i32* %57, i32** %10
%58 = load i32*, i32** %10
%59 = icmp ne i32* %58, null
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
store i32 0, i32* %9
br label %62
62: ; preds = %86, %50
%63 = load i32, i32* %9
%64 = load i32, i32* %7
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %87
66: ; preds = %62
%67 = call i32 (...) @rand()
%68 = load i32, i32* %6
%69 = srem i32 %67, %68
%70 = add nsw i32 1, %69
store i32 %70, i32* %8
%71 = load i32*, i32** %10
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = icmp ne i32 %75, 0
br i1 %76, label %86, label %77
77: ; preds = %66
%78 = load i32, i32* %8
%79 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %78)
%80 = load i32*, i32** %10
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
store i32 1, i32* %83
%84 = load i32, i32* %9
%85 = add nsw i32 %84, 1
store i32 %85, i32* %9
br label %86
86: ; preds = %77, %66
br label %62
87: ; preds = %62
%88 = load i32, i32* @EXIT_SUCCESS
store i32 %88, i32* %3
br label %89
89: ; preds = %87, %43, %33, %13
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s max nvals seed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%s: nvals << max\0A\00"
@.str.2 = [19 x i8] c"%s: nvals <= 1000\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %40, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = sdiv i32 %7, 3
%12 = icmp sgt i32 %10, %11
br i1 %12, label %40, label %13
13: ; preds = %4
%14 = icmp sgt i32 %10, 1000
br i1 %14, label %40, label %15
15: ; preds = %13
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 @srand(i32 %18)
%20 = tail call i32* @calloc(i32 %10, i32 4)
%21 = icmp ne i32* %20, null
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = icmp sgt i32 %10, 0
br i1 %24, label %25, label %45
25: ; preds = %15, %37
%26 = phi i32 [ %38, %37 ], [ 0, %15 ]
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, %7
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %20, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
store i32 1, i32* %31
%36 = add nsw i32 %26, 1
br label %37
37: ; preds = %34, %25
%38 = phi i32 [ %26, %25 ], [ %36, %34 ]
%39 = icmp slt i32 %38, %10
br i1 %39, label %25, label %45
40: ; preds = %13, %4, %2
%41 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %13 ]
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %1
%44 = tail call i32 @fprintf(i32 %42, i8* %41, i8* %43)
br label %45
45: ; preds = %37, %40, %15
%46 = phi i32* [ @EXIT_SUCCESS, %15 ], [ @EXIT_FAILURE, %40 ], [ @EXIT_SUCCESS, %37 ]
%47 = load i32, i32* %46
ret i32 %47
}