#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 *, ...);
scalar_t__ memcmp(char const *, char const *, size_t);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void argmatch_valid(const char *const *arglist, const char *vallist,
                    size_t valsize) {
  int i;
  const char *last_val = NULL;
  fprintf(stderr, "Valid arguments are:");
  for (i = 0; arglist[i]; i++)
    if ((i == 0) || memcmp(last_val, vallist + valsize * i, valsize)) {
      fprintf(stderr, "\n  - `%s'", arglist[i]);
      last_val = vallist + valsize * i;
    } else {
      fprintf(stderr, ", `%s'", arglist[i]);
    }
  putc('\n', stderr);
}


x86 assembly (clang, -O0):
<argmatch_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1226 <argmatch_valid+0xf6>
cmpl   $0x0,-0x1c(%rbp)
je     11b1 <argmatch_valid+0x81>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   %rcx,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11f0 <argmatch_valid+0xc0>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1213 <argmatch_valid+0xe3>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1218 <argmatch_valid+0xe8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <argmatch_valid+0x3a>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argmatch_valid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e95(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%rdx
test   %rdx,%rdx
je     11e8 <argmatch_valid+0xb8>
mov    0x0(%r13),%edi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpq   $0x0,0x8(%r12)
je     11e8 <argmatch_valid+0xb8>
lea    (%r15,%r14,1),%rbx
add    $0x10,%r12
lea    0xe82(%rip),%rbp
jmp    11bd <argmatch_valid+0x8d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    %r14,%rbx
cmpq   $0x0,(%r12)
lea    0x8(%r12),%r12
je     11e8 <argmatch_valid+0xb8>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <memcmp@plt>
mov    0x0(%r13),%edi
mov    -0x8(%r12),%rdx
test   %rax,%rax
je     11a0 <argmatch_valid+0x70>
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%r15
jmp    11ae <argmatch_valid+0x7e>
mov    0x0(%r13),%esi
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putc@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Valid arguments are:\00"
@.str.1 = [10 x i8] c"\0A - `%s'\00"
@.str.2 = [7 x i8] c", `%s'\00"
define void @argmatch_valid(i8** %0, i8* %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* null, i8** %8
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %11
11: ; preds = %55, %3
%12 = load i8**, i8*** %4
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %58
18: ; preds = %11
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = mul i64 %24, %26
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = load i64, i64* %6
%30 = call i64 @memcmp(i8* %22, i8* %28, i64 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %21, %18
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %5
%41 = load i64, i64* %6
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = mul i64 %41, %43
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8* %45, i8** %8
br label %54
46: ; preds = %21
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %46, %32
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %11
58: ; preds = %11
%59 = load i32, i32* @stderr
%60 = call i32 @putc(i8 signext 10, i32 %59)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Valid arguments are:\00"
@.str.1 = [10 x i8] c"\0A - `%s'\00"
@.str.2 = [7 x i8] c", `%s'\00"
define void @argmatch_valid(i8** nocapture %0, i8* %1, i64 %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %37, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = getelementptr inbounds i8*, i8** %0, i64 1
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %37, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8*, i8** %0, i64 1
br label %16
16: ; preds = %31, %14
%17 = phi i64 [ 1, %14 ], [ %33, %31 ]
%18 = phi i8** [ %15, %14 ], [ %34, %31 ]
%19 = phi i8* [ %1, %14 ], [ %32, %31 ]
%20 = mul i64 %17, %2
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = tail call i64 @memcmp(i8* %19, i8* %21, i64 %2)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %18
br i1 %23, label %29, label %26
26: ; preds = %16
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%28 = getelementptr inbounds i8, i8* %1, i64 %20
br label %31
29: ; preds = %16
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %31
31: ; preds = %26, %29
%32 = phi i8* [ %28, %26 ], [ %19, %29 ]
%33 = add nuw i64 %17, 1
%34 = getelementptr inbounds i8*, i8** %0, i64 %33
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %16
37: ; preds = %31, %8, %3
%38 = load i32, i32* @stderr
%39 = tail call i32 @putc(i8 signext 10, i32 %38)
ret void
}