#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 */
typedef int /*<<< orphan*/ errbuf;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ ERR_error_string_n(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ERR_get_error();
int RAND_bytes(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int ac, char **av) {
  if (ac < 2) {
    fprintf(stderr, "usage: %s {salt-length}\n", av[0]);
    exit(1);
  }
  char *salt_length_str = av[1];
  int salt_length = 0;
  sscanf(salt_length_str, "%d", &salt_length);
  if (salt_length <= 0) {
    fprintf(stderr, "%s: salt length must be greater than 0\n", av[0]);
    exit(1);
  }
  char *salt = malloc(salt_length);
  if (salt == NULL) {
    fprintf(stderr, "%s: could not allocate memory for salt of length %d\n",
            av[0], salt_length);
    exit(1);
  }
  int ok = RAND_bytes(salt, salt_length);
  if (!ok) {
    char errbuf[1024];
    ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
    fprintf(stderr, "%s: could not generate %d random bytes: '%s'\n", av[0],
            salt_length, errbuf);
    exit(1);
  }
  BIO *bio, *b64;
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bio = BIO_new_fp(stdout, BIO_NOCLOSE);
  BIO_push(b64, bio);
  BIO_write(b64, salt, salt_length);
  BIO_flush(b64);
  fprintf(stdout, "\n");
  BIO_free_all(b64);
  free(salt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    124b <main+0x4b>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdb0(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   10d0 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     12a4 <main+0xa4>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12e6 <main+0xe6>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <RAND_bytes@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    134b <main+0x14b>
mov    $0x0,%al
call   10e0 <ERR_get_error@plt>
mov    %eax,%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <ERR_error_string_n@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x430(%rbp),%r8
lea    0xd3f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rdi
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
call   1090 <BIO_set_flags@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
mov    0x2c63(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
mov    %rax,-0x438(%rbp)
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   1050 <BIO_push@plt>
mov    -0x440(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1110 <BIO_write@plt>
mov    -0x440(%rbp),%rdi
call   1120 <BIO_flush@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x440(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    12f2 <main+0xf2>
mov    0x8(%r14),%rdi
movl   $0x0,0xc(%rsp)
lea    0xdee(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10d0 <sscanf@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
jle    1307 <main+0x107>
mov    %ebx,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     132b <main+0x12b>
mov    %rax,%r15
mov    %rax,%rdi
mov    %ebx,%esi
call   1070 <RAND_bytes@plt>
test   %eax,%eax
je     1351 <main+0x151>
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <BIO_set_flags@plt>
mov    0x2d39(%rip),%r14
mov    (%r14),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <BIO_push@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1110 <BIO_write@plt>
mov    %rbx,%rdi
call   1120 <BIO_flush@plt>
mov    (%r14),%edi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   10f0 <BIO_free_all@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcfb(%rip),%rsi
jmp    131a <main+0x11a>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd02(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd06(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
xor    %eax,%eax
call   10e0 <ERR_get_error@plt>
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <ERR_error_string_n@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0xc(%rsp),%ecx
lea    0xcf6(%rip),%rsi
mov    %rbx,%r8
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s {salt-length}\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"%s: salt length must be greater than 0\0A\00"
@.str.3 = [53 x i8] c"%s: could not allocate memory for salt of length %d\0A\00"
@.str.4 = [46 x i8] c"%s: could not generate %d random bytes: '%s'\0A\00"
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %6
store i32 0, i32* %7
%26 = load i8*, i8** %6
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%28 = load i32, i32* %7
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %22
%38 = load i32, i32* %7
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %50
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = load i32, i32* %7
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %46, i32 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %37
%51 = load i8*, i8** %8
%52 = load i32, i32* %7
%53 = call i32 @RAND_bytes(i8* %51, i32 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp ne i32 %54, 0
br i1 %55, label %68, label %56
56: ; preds = %50
%57 = call i32 (...) @ERR_get_error()
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%59 = call i32 @ERR_error_string_n(i32 %57, i8* %58, i32 1024)
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = load i32, i32* %7
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %63, i32 %64, i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %50
%69 = call i32 (...) @BIO_f_base64()
%70 = call i32* @BIO_new(i32 %69)
store i32* %70, i32** %12
%71 = load i32*, i32** %12
%72 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%73 = call i32 @BIO_set_flags(i32* %71, i32 %72)
%74 = load i32, i32* @stdout
%75 = load i32, i32* @BIO_NOCLOSE
%76 = call i32* @BIO_new_fp(i32 %74, i32 %75)
store i32* %76, i32** %11
%77 = load i32*, i32** %12
%78 = load i32*, i32** %11
%79 = call i32 @BIO_push(i32* %77, i32* %78)
%80 = load i32*, i32** %12
%81 = load i8*, i8** %8
%82 = load i32, i32* %7
%83 = call i32 @BIO_write(i32* %80, i8* %81, i32 %82)
%84 = load i32*, i32** %12
%85 = call i32 @BIO_flush(i32* %84)
%86 = load i32, i32* @stdout
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%88 = load i32*, i32** %12
%89 = call i32 @BIO_free_all(i32* %88)
%90 = load i8*, i8** %8
%91 = call i32 @free(i8* %90)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s {salt-length}\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"%s: salt length must be greater than 0\0A\00"
@.str.3 = [53 x i8] c"%s: could not allocate memory for salt of length %d\0A\00"
@.str.4 = [46 x i8] c"%s: could not generate %d random bytes: '%s'\0A\00"
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%15 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = call i8* @malloc(i32 %16)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 %16)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = call i32 @RAND_bytes(i8* %24, i32 %16)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i32 (...) @ERR_get_error()
%37 = call i32 @ERR_error_string_n(i32 %36, i8* %35, i32 1024)
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %1
%40 = load i32, i32* %3
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %40, i8* %35)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %31
%44 = call i32 (...) @BIO_f_base64()
%45 = call i32* @BIO_new(i32 %44)
%46 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%47 = call i32 @BIO_set_flags(i32* %45, i32 %46)
%48 = load i32, i32* @stdout
%49 = load i32, i32* @BIO_NOCLOSE
%50 = call i32* @BIO_new_fp(i32 %48, i32 %49)
%51 = call i32 @BIO_push(i32* %45, i32* %50)
%52 = load i32, i32* %3
%53 = call i32 @BIO_write(i32* %45, i8* %24, i32 %52)
%54 = call i32 @BIO_flush(i32* %45)
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @BIO_free_all(i32* %45)
%58 = call i32 @free(i8* %24)
ret i32 0
}