#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int filekey(int n_bytes, char *path) {
  int fd;
  if ((fd = open(path, O_WRONLY)) < 0) {
    printf("Error: Al abrir %s\n", path);
    return -1;
  }
  char key[n_bytes];
  srand(time(NULL));
  int i;
  for (i = 0; i < n_bytes; i++) {
    key[i] = rand() % 126 + 33;
  }
  write(fd, key, n_bytes);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<filekey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b9 <filekey+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <filekey+0xe2>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122d <filekey+0xbd>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x7e,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
add    $0x21,%edx
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f6 <filekey+0x86>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filekey>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     122c <filekey+0xbc>
mov    %eax,%r12d
mov    %rsp,-0x30(%rbp)
mov    %r14d,%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
test   %r14d,%r14d
jle    120e <filekey+0x9e>
xor    %r15d,%r15d
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0xffffffff82082083,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x7,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
add    $0x21,%sil
mov    %sil,(%rbx,%r15,1)
add    $0x1,%r15
cmp    %r15,%r13
jne    11d0 <filekey+0x60>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
jmp    1240 <filekey+0xd0>
lea    0xdcd(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [20 x i8] c"Error: Al abrir %s\0A\00"
define i32 @filekey(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %46
17: ; preds = %2
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8, i64 %19
store i64 %19, i64* %8
%22 = call i32 @time(i32* null)
%23 = call i32 @srand(i32 %22)
store i32 0, i32* %9
br label %24
24: ; preds = %36, %17
%25 = load i32, i32* %9
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 126
%31 = add nsw i32 %30, 33
%32 = trunc i32 %31 to i8
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %21, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %28
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %24
39: ; preds = %24
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = call i32 @write(i32 %40, i8* %21, i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
%45 = load i8*, i8** %7
br label %46
46: ; preds = %39, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [20 x i8] c"Error: Al abrir %s\0A\00"
define i32 @filekey(i32 %0, i8* %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* %1, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %27
8: ; preds = %2
%9 = zext i32 %0 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = tail call i32 @time(i32* null)
%13 = tail call i32 @srand(i32 %12)
%14 = icmp sgt i32 %0, 0
br i1 %14, label %15, label %24
15: ; preds = %8, %15
%16 = phi i64 [ %22, %15 ], [ 0, %8 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 126
%19 = trunc i32 %18 to i8
%20 = add i8 %19, 33
%21 = getelementptr inbounds i8, i8* %11, i64 %16
store i8 %20, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %9
br i1 %23, label %24, label %15
24: ; preds = %15, %8
%25 = call i32 @write(i32 %4, i8* %11, i32 %0)
%26 = tail call i32 @close(i32 %4)
tail call void @llvm.stackrestore(i8* %10)
br label %27
27: ; preds = %24, %6
%28 = phi i32 [ -1, %6 ], [ 0, %24 ]
ret i32 %28
}