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

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
unsigned int get_random_script(void) {
  char str_cmd[128] = "cat /dev/urandom| tr -dc '0-5' | fold -w 2 | head -n 1";
  char str_buf[1024];
  FILE *fd;
  fd = popen(str_cmd, "r");
  while (fgets(str_buf, 1024, fd) != NULL)
    return (atoi(str_buf));
}


x86 assembly (clang, -O0):
<get_random_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
lea    -0x90(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x80,%edx
call   1040 <memcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xf0f(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x498(%rbp)
lea    -0x490(%rbp),%rdi
mov    -0x498(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11ae <get_random_script+0x6e>
lea    -0x490(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random_script>:
sub    $0x488,%rsp
movaps 0xf32(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xf16(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xefa(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe6e(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee3(%rip),%rsi
mov    %rsp,%rdi
call   1040 <popen@plt>
lea    0x80(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11d4 <get_random_script+0xa4>
lea    0x80(%rsp),%rdi
call   1050 <atoi@plt>
add    $0x488,%rsp
ret
add    $0x488,%rsp
ret

LLVM IR (-O0):
@__const.get_random_script.str_cmd = [128 x i8] c"cat /dev/urandom| tr -dc '0-5' | fold -w 2 | head -n 1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"r\00"
define i32 @get_random_script() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32*
%5 = bitcast [128 x i8]* %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
br label %8
8: ; preds = %0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %4
%11 = call i32* @fgets(i8* %9, i32 1024, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %1
br label %16
16: ; preds = %13, %8
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@__const.get_random_script.str_cmd = [128 x i8] c"cat /dev/urandom| tr -dc '0-5' | fold -w 2 | head -n 1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"r\00"
define i32 @get_random_script() {
%1 = alloca [128 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @atoi(i8* %4)
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ %9, %8 ], [ undef, %0 ]
ret i32 %11
}