#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *getenv(char const *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ is_positive_numeric(char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ srandom(int);
int get_percentage_env(const char *name) {
  char *env;
  struct timeval t;
  int result;
  gettimeofday(&t, NULL);
  srandom(t.tv_sec ^ t.tv_usec);
  env = getenv(name);
  if (env) {
    result = atoi(env);
    if ((!is_positive_numeric(env)) || result > 100) {
      printf("%s must be a valid percentage (0-100).\n", name);
      exit(EXIT_FAILURE);
    }
  } else
    result = 0;
  return result;
}


x86 assembly (clang, -O0):
<get_percentage_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
xor    -0x14(%rbp),%edi
call   1050 <srandom@plt>
mov    -0x8(%rbp),%rdi
call   1040 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f7 <get_percentage_env+0x87>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <is_positive_numeric@plt>
cmp    $0x0,%eax
je     11d4 <get_percentage_env+0x64>
cmpl   $0x64,-0x1c(%rbp)
jle    11f2 <get_percentage_env+0x82>
mov    -0x8(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1060 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11fe <get_percentage_env+0x8e>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_percentage_env>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %r15d,%r15d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0xc(%rsp),%edi
xor    0x8(%rsp),%edi
call   1050 <srandom@plt>
mov    %r14,%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     11c5 <get_percentage_env+0x55>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <is_positive_numeric@plt>
test   %eax,%eax
je     11d2 <get_percentage_env+0x62>
cmp    $0x65,%r15d
jge    11d2 <get_percentage_env+0x62>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [40 x i8] c"%s must be a valid percentage (0-100).\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_percentage_env(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.timeval
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%10 = load i32, i32* %9
%11 = xor i32 %8, %10
%12 = call i32 @srandom(i32 %11)
%13 = load i8*, i8** %2
%14 = call i8* @getenv(i8* %13)
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %32
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %5
%20 = load i8*, i8** %3
%21 = call i32 @is_positive_numeric(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 100
br i1 %25, label %26, label %31
26: ; preds = %23, %17
%27 = load i8*, i8** %2
%28 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
br label %33
32: ; preds = %1
store i32 0, i32* %5
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [40 x i8] c"%s must be a valid percentage (0-100).\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_percentage_env(i8* %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = xor i32 %8, %6
%10 = tail call i32 @srandom(i32 %9)
%11 = tail call i8* @getenv(i8* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %1
%14 = tail call i32 @atoi(i8* %11)
%15 = tail call i32 @is_positive_numeric(i8* %11)
%16 = icmp eq i32 %15, 0
%17 = icmp sgt i32 %14, 100
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %1, %13
%24 = phi i32 [ %14, %13 ], [ 0, %1 ]
ret i32 %24
}