#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 EXIT_FAILURE;
int EXIT_SUCCESS;
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ RNDADDTOENTCNT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int add_entropy_cnt(int fd, int argc, char *argv[]) {
  int val;
  int r;
  if (argc != 2) {
    fprintf(stderr, "Incorrect amount of arguments\n");
    usage();
    return EXIT_FAILURE;
  }
  char *endptr = NULL;
  long cnt = strtol(argv[1], &endptr, 0);
  if (*endptr != '\0') {
    fprintf(stderr, "Numeric argument contains non-numeric "
                    "characters\n");
    return EXIT_FAILURE;
  }
  if (cnt == LONG_MIN) {
    fprintf(stderr, "Numeric argument to small\n");
    return EXIT_FAILURE;
  }
  if (cnt == LONG_MAX) {
    fprintf(stderr, "Numeric argument to big\n");
    return EXIT_FAILURE;
  }
  val = cnt;
  r = ioctl(fd, RNDADDTOENTCNT, &val);
  if (r != 0) {
    perror("RNDADDTOENTCNT failed");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<add_entropy_cnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
je     1199 <add_entropy_cnt+0x49>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <add_entropy_cnt+0x164>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ee <add_entropy_cnt+0x9e>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <add_entropy_cnt+0x164>
mov    -0x30(%rbp),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    1228 <add_entropy_cnt+0xd8>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <add_entropy_cnt+0x164>
mov    -0x30(%rbp),%rax
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%rax
jne    1262 <add_entropy_cnt+0x112>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <add_entropy_cnt+0x164>
mov    -0x30(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12a8 <add_entropy_cnt+0x158>
lea    0xdf3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <add_entropy_cnt+0x164>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_entropy_cnt>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%esi
jne    1196 <add_entropy_cnt+0x46>
mov    %edi,%ebx
movq   $0x0,0x8(%rsp)
mov    0x8(%rdx),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     11c1 <add_entropy_cnt+0x71>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b2 <add_entropy_cnt+0x62>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jne    11e4 <add_entropy_cnt+0x94>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b2 <add_entropy_cnt+0x62>
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%rax
jne    1207 <add_entropy_cnt+0xb7>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b2 <add_entropy_cnt+0x62>
mov    %eax,0x4(%rsp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    122d <add_entropy_cnt+0xdd>
mov    0x2d95(%rip),%rax
jmp    11b9 <add_entropy_cnt+0x69>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
jmp    11b2 <add_entropy_cnt+0x62>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Incorrect amount of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"Numeric argument contains non-numeric characters\0A\00"
@LONG_MIN = global i64 0
@.str.2 = [27 x i8] c"Numeric argument to small\0A\00"
@LONG_MAX = global i64 0
@.str.3 = [25 x i8] c"Numeric argument to big\0A\00"
@RNDADDTOENTCNT = global i32 0
@.str.4 = [22 x i8] c"RNDADDTOENTCNT failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @add_entropy_cnt(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @usage()
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %4
br label %61
19: ; preds = %3
store i8* null, i8** %10
%20 = load i8**, i8*** %7
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strtol(i8* %22, i8** %10, i32 0)
store i64 %23, i64* %11
%24 = load i8*, i8** %10
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %4
br label %61
32: ; preds = %19
%33 = load i64, i64* %11
%34 = load i64, i64* @LONG_MIN
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %4
br label %61
40: ; preds = %32
%41 = load i64, i64* %11
%42 = load i64, i64* @LONG_MAX
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %4
br label %61
48: ; preds = %40
%49 = load i64, i64* %11
%50 = trunc i64 %49 to i32
store i32 %50, i32* %8
%51 = load i32, i32* %5
%52 = load i32, i32* @RNDADDTOENTCNT
%53 = call i32 @ioctl(i32 %51, i32 %52, i32* %8)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %4
br label %61
59: ; preds = %48
%60 = load i32, i32* @EXIT_SUCCESS
store i32 %60, i32* %4
br label %61
61: ; preds = %59, %56, %44, %36, %28, %14
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Incorrect amount of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"Numeric argument contains non-numeric characters\0A\00"
@LONG_MIN = global i64 0
@.str.2 = [27 x i8] c"Numeric argument to small\0A\00"
@LONG_MAX = global i64 0
@.str.3 = [25 x i8] c"Numeric argument to big\0A\00"
@RNDADDTOENTCNT = global i32 0
@.str.4 = [22 x i8] c"RNDADDTOENTCNT failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @add_entropy_cnt(i32 %0, i32 %1, i8** nocapture %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %1, 2
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (...) @usage()
%12 = load i32, i32* @EXIT_FAILURE
br label %46
13: ; preds = %3
%14 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%15 = getelementptr inbounds i8*, i8** %2, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strtol(i8* %16, i8** %5, i32 0)
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %43
24: ; preds = %13
%25 = load i64, i64* @LONG_MIN
%26 = icmp eq i64 %17, %25
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %43
30: ; preds = %24
%31 = load i64, i64* @LONG_MAX
%32 = icmp eq i64 %17, %31
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %43
36: ; preds = %30
%37 = trunc i64 %17 to i32
store i32 %37, i32* %4
%38 = load i32, i32* @RNDADDTOENTCNT
%39 = call i32 @ioctl(i32 %0, i32 %38, i32* %4)
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %36, %41, %33, %27, %21
%44 = phi i32* [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %27 ], [ @EXIT_FAILURE, %33 ], [ @EXIT_FAILURE, %41 ], [ @EXIT_SUCCESS, %36 ]
%45 = load i32, i32* %44
br label %46
46: ; preds = %43, %8
%47 = phi i32 [ %12, %8 ], [ %45, %43 ]
ret i32 %47
}