#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
bool validateArgs(int argc, char **argv, int required_count,
                  void (*helpFn)(void)) {
  fprintf(stderr, "Validating arguments...\n");
  if (argc != required_count) {
    fprintf(stderr,
            "Need %d argument(s) for the test. %d argument(s) provided.\n",
            required_count, argc);
    fprintf(stderr, "Dumping supplied argument(s):\n");
    for (int i = 0; i < argc; ++i) {
      fprintf(stderr, "Arg %d: %s\n", i + 1, argv[i]);
    }
    if (helpFn) {
      helpFn();
    }
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<validateArgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11e1 <validateArgs+0xd1>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xeba(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xedf(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c7 <validateArgs+0xb7>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xec2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <validateArgs+0x74>
cmpq   $0x0,-0x20(%rbp)
je     11d5 <validateArgs+0xc5>
call   *-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    11e8 <validateArgs+0xd8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateArgs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb3(%rip),%r13
mov    0x0(%r13),%edi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r15d
cmp    %r12d,%ebp
je     11b8 <validateArgs+0xa8>
mov    %r14,(%rsp)
mov    0x0(%r13),%edi
lea    0xec0(%rip),%rsi
xor    %r15d,%r15d
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xee2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %ebp,%ebp
jle    11ad <validateArgs+0x9d>
mov    %ebp,%r14d
lea    0xeec(%rip),%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%rbx,%rbp,8),%rcx
add    $0x1,%rbp
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %rbp,%r14
jne    1190 <validateArgs+0x80>
mov    (%rsp),%rax
test   %rax,%rax
je     11b8 <validateArgs+0xa8>
call   *%rax
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Validating arguments...\0A\00"
@.str.1 = [60 x i8] c"Need %d argument(s) for the test. %d argument(s) provided.\0A\00"
@.str.2 = [31 x i8] c"Dumping supplied argument(s):\0A\00"
@.str.3 = [12 x i8] c"Arg %d: %s\0A\00"
define i32 @validateArgs(i32 %0, i8** %1, i32 %2, void ()* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca void ()*
%10 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store void ()* %3, void ()** %9
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %6
%14 = load i32, i32* %8
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %46
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %10
br label %23
23: ; preds = %37, %16
%24 = load i32, i32* %10
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
%31 = load i8**, i8*** %7
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %30, i8* %35)
br label %37
37: ; preds = %27
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %23
40: ; preds = %23
%41 = load void ()*, void ()** %9
%42 = icmp ne void ()* %41, null
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load void ()*, void ()** %9
br label %45
45: ; preds = %43, %40
store i32 0, i32* %5
br label %47
46: ; preds = %4
store i32 1, i32* %5
br label %47
47: ; preds = %46, %45
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Validating arguments...\0A\00"
@.str.1 = [60 x i8] c"Need %d argument(s) for the test. %d argument(s) provided.\0A\00"
@.str.2 = [31 x i8] c"Dumping supplied argument(s):\0A\00"
@.str.3 = [12 x i8] c"Arg %d: %s\0A\00"
define i32 @validateArgs(i32 %0, i8** nocapture %1, i32 %2, void ()* %3) {
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %0, %2
br i1 %7, label %28, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %0)
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = zext i32 %0 to i64
br label %18
16: ; preds = %18, %8
%17 = icmp eq void ()* %3, null
br i1 %17, label %28, label %27
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %21, %18 ]
%20 = load i32, i32* @stderr
%21 = add nuw nsw i64 %19, 1
%22 = getelementptr inbounds i8*, i8** %1, i64 %19
%23 = load i8*, i8** %22
%24 = trunc i64 %21 to i32
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %23)
%26 = icmp eq i64 %21, %15
br i1 %26, label %16, label %18
27: ; preds = %16
tail call void %3()
br label %28
28: ; preds = %4, %16, %27
%29 = phi i32 [ 0, %27 ], [ 0, %16 ], [ 1, %4 ]
ret i32 %29
}