#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*/ buf;

/* Variables and functions */
int errno;
int getentropy(char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main() {
  char buf[16];
  memset(buf, 0, sizeof(buf));
  int i = getentropy(buf, sizeof(buf) - 1);
  if (i == -1) {
    perror("getentropy");
    return errno;
  }
  printf("%s\n", buf);
  printf("%ld\n", strlen(buf));
  for (int j = 0; j < sizeof(buf); ++j) {
    printf("%d ", buf[j]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rdi
mov    $0xf,%esi
call   1030 <getentropy@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11a7 <main+0x57>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <main+0xd1>
lea    -0x20(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    $0x10,%rax
jae    120c <main+0xbc>
movslq -0x28(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d9 <main+0x89>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
call   1050 <getentropy@plt>
cmp    $0xffffffff,%eax
je     12cc <main+0x15c>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xe51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl (%rsp),%esi
lea    0xe42(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x1(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x2(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x3(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x5(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x6(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x7(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xd(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xe(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd2d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%ebp
jmp    12c3 <main+0x153>

LLVM IR (-O0):
@.str = [11 x i8] c"getentropy\00"
@errno = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 16)
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%8 = call i32 @getentropy(i8* %7, i32 15)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
store i32 %13, i32* %1
br label %36
14: ; preds = %0
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 0, i32* %4
br label %20
20: ; preds = %31, %14
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 16
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %20
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %36
36: ; preds = %34, %11
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [11 x i8] c"getentropy\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 16)
%4 = call i32 @getentropy(i8* %2, i32 15)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @errno
br label %77
9: ; preds = %0
%10 = call i32 @puts(i8* %2)
%11 = call i32 @strlen(i8* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 6
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 7
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 8
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 9
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 10
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 11
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 12
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 13
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 14
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 15
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %74)
%76 = call i32 @putchar(i32 10)
br label %77
77: ; preds = %9, %6
%78 = phi i32 [ %8, %6 ], [ 0, %9 ]
ret i32 %78
}