#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*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int x[8];
  printf("Gerando 10 valores aleatorios:\n");
  for (int i = 0; i < 8; i++) {
    scanf("%d", &x[i]);
    if (x[i] == 3) {
      int sorteado = -1;
      while ((sorteado = rand() % 8) != i)
        ;
      x[i] = sorteado;
    } else {
      x[i] = rand() % 8;
    }
    printf("[%d] = %d\n", i, x[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    11fd <main+0xcd>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xeac(%rip),%rdi
call   1040 <scanf@plt>
movslq -0x34(%rbp),%rax
cmpl   $0x3,-0x30(%rbp,%rax,4)
jne    11bf <main+0x8f>
movl   $0xffffffff,-0x38(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%rbp)
cmp    -0x34(%rbp),%edx
je     11af <main+0x7f>
jmp    118f <main+0x5f>
mov    -0x38(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    11d6 <main+0xa6>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
movslq -0x34(%rbp),%rax
mov    %edx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%esi
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1154 <main+0x24>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%r14
lea    0xea0(%rip),%r15
xor    %ebx,%ebx
jmp    119f <main+0x5f>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x8,%rbx
je     11db <main+0x9b>
lea    (%rsp,%rbx,4),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
cmpl   $0x3,(%rsp,%rbx,4)
jne    1170 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
cmp    %rax,%rbx
jne    11c0 <main+0x80>
jmp    1184 <main+0x44>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Gerando 10 valores aleatorios:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %44, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %47
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %31
19: ; preds = %9
store i32 -1, i32* %4
br label %20
20: ; preds = %25, %19
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 8
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20
br label %20
26: ; preds = %20
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %29
store i32 %27, i32* %30
br label %37
31: ; preds = %9
%32 = call i32 (...) @rand()
%33 = srem i32 %32, 8
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %35
store i32 %33, i32* %36
br label %37
37: ; preds = %31, %26
%38 = load i32, i32* %3
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %42)
br label %44
44: ; preds = %37
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %6
47: ; preds = %6
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"[%d] = %d\0A\00"
@str = [31 x i8] c"Gerando 10 valores aleatorios:\00"
define i32 @main() {
%1 = alloca [8 x i32]
%2 = bitcast [8 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %5
4: ; preds = %19
ret i32 0
5: ; preds = %0, %19
%6 = phi i64 [ 0, %0 ], [ %23, %19 ]
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 %6
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %5, %11
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 8
%14 = zext i32 %13 to i64
%15 = icmp eq i64 %6, %14
br i1 %15, label %19, label %11
16: ; preds = %5
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 8
br label %19
19: ; preds = %11, %16
%20 = phi i32 [ %18, %16 ], [ %13, %11 ]
store i32 %20, i32* %7
%21 = trunc i64 %6 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %20)
%23 = add nuw nsw i64 %6, 1
%24 = icmp eq i64 %23, 8
br i1 %24, label %4, label %5
}