#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
void chkval(int ct, int c, int expchar, char *extra, char *expextra, int optnum,
            int expnum, const char *testid) {
  int err = 0;
  if (c != expchar) {
    err++;
    printf("Mismatch %d %s: got char %c 0x%x exp char %c 0x%x\n", ct, testid, c,
           c, expchar, expchar);
  }
  if (extra != expextra) {
    if (extra && expextra && (!strcmp(extra, expextra))) {
    } else {
      err++;
      printf("Mismatch %d %s: got optarg %s 0x%x exp optarg %s 0x%x\n", ct,
             testid, extra ? extra : "", (unsigned)extra,
             expextra ? expextra : "", (unsigned)expextra);
    }
  }
  if (optnum != expnum) {
    err++;
    printf("Mismatch %d %s: got optind %d 0x%x exp optind %d 0x%x\n", ct,
           testid, optnum, optnum, expnum, expnum);
  }
  if (err > 0) {
    printf("FAIL getopttest %s\n", testid);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<chkval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1196 <chkval+0x66>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    -0xc(%rbp),%eax
lea    0xe74(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1278 <chkval+0x148>
cmpq   $0x0,-0x18(%rbp)
je     11d5 <chkval+0xa5>
cmpq   $0x0,-0x20(%rbp)
je     11d5 <chkval+0xa5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11d5 <chkval+0xa5>
jmp    1273 <chkval+0x143>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1204 <chkval+0xd4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1214 <chkval+0xe4>
lea    0xea9(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1214 <chkval+0xe4>
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123b <chkval+0x10b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    124b <chkval+0x11b>
lea    0xe72(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    124b <chkval+0x11b>
mov    -0x44(%rbp),%r8d
mov    -0x50(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%esi
mov    -0x58(%rbp),%r9
mov    -0x20(%rbp),%rax
lea    0xdca(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1278 <chkval+0x148>
mov    -0x24(%rbp),%eax
cmp    0x10(%rbp),%eax
je     12b3 <chkval+0x183>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    0x10(%rbp),%eax
lea    0xdc1(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x28(%rbp)
jle    12d9 <chkval+0x1a9>
mov    0x18(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chkval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r13d
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
cmp    %edx,%esi
je     1174 <chkval+0x44>
mov    %r14d,(%rsp)
lea    0xea4(%rip),%rdi
mov    %r15d,%esi
mov    0x48(%rsp),%rdx
mov    %r12d,%ecx
mov    %r12d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x40(%rsp),%r9d
cmp    %rbp,%rbx
je     119c <chkval+0x6c>
test   %rbx,%rbx
je     11b5 <chkval+0x85>
test   %rbp,%rbp
je     11b5 <chkval+0x85>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
mov    0x40(%rsp),%r9d
test   %eax,%eax
jne    11b5 <chkval+0x85>
cmp    %r9d,%r13d
jne    11f4 <chkval+0xc4>
cmp    %r14d,%r12d
jne    1214 <chkval+0xe4>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbx,%rbx
mov    %r9d,%r14d
lea    0xef2(%rip),%r9
mov    %r9,%rcx
cmovne %rbx,%rcx
test   %rbp,%rbp
cmovne %rbp,%r9
mov    %ebp,(%rsp)
lea    0xe59(%rip),%rdi
mov    %r15d,%esi
mov    0x48(%rsp),%rdx
mov    %ebx,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%r9d
cmp    %r14d,%r13d
je     1214 <chkval+0xe4>
mov    %r9d,(%rsp)
lea    0xe6b(%rip),%rdi
mov    %r15d,%esi
mov    0x48(%rsp),%rdx
mov    %r13d,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
mov    0x48(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"Mismatch %d %s: got char %c 0x%x exp char %c 0x%x\0A\00"
@.str.1 = [55 x i8] c"Mismatch %d %s: got optarg %s 0x%x exp optarg %s 0x%x\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [55 x i8] c"Mismatch %d %s: got optind %d 0x%x exp optind %d 0x%x\0A\00"
@.str.4 = [20 x i8] c"FAIL getopttest %s\0A\00"
define void @chkval(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i32 %5, i32 %6, i8* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i8* %7, i8** %16
store i32 0, i32* %17
%18 = load i32, i32* %10
%19 = load i32, i32* %11
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %8
%22 = load i32, i32* %17
%23 = add nsw i32 %22, 1
store i32 %23, i32* %17
%24 = load i32, i32* %9
%25 = load i8*, i8** %16
%26 = load i32, i32* %10
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = load i32, i32* %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %24, i8* %25, i32 %26, i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %21, %8
%32 = load i8*, i8** %12
%33 = load i8*, i8** %13
%34 = icmp ne i8* %32, %33
br i1 %34, label %35, label %72
35: ; preds = %31
%36 = load i8*, i8** %12
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load i8*, i8** %13
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8*, i8** %12
%43 = load i8*, i8** %13
%44 = call i32 @strcmp(i8* %42, i8* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %41
br label %71
47: ; preds = %41, %38, %35
%48 = load i32, i32* %17
%49 = add nsw i32 %48, 1
store i32 %49, i32* %17
%50 = load i32, i32* %9
%51 = load i8*, i8** %16
%52 = load i8*, i8** %12
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = load i8*, i8** %12
br label %57
56: ; preds = %47
br label %57
57: ; preds = %56, %54
%58 = phi i8* [ %55, %54 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %56 ]
%59 = load i8*, i8** %12
%60 = ptrtoint i8* %59 to i32
%61 = load i8*, i8** %13
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = load i8*, i8** %13
br label %66
65: ; preds = %57
br label %66
66: ; preds = %65, %63
%67 = phi i8* [ %64, %63 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %65 ]
%68 = load i8*, i8** %13
%69 = ptrtoint i8* %68 to i32
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %50, i8* %51, i8* %58, i32 %60, i8* %67, i32 %69)
br label %71
71: ; preds = %66, %46
br label %72
72: ; preds = %71, %31
%73 = load i32, i32* %14
%74 = load i32, i32* %15
%75 = icmp ne i32 %73, %74
br i1 %75, label %76, label %86
76: ; preds = %72
%77 = load i32, i32* %17
%78 = add nsw i32 %77, 1
store i32 %78, i32* %17
%79 = load i32, i32* %9
%80 = load i8*, i8** %16
%81 = load i32, i32* %14
%82 = load i32, i32* %14
%83 = load i32, i32* %15
%84 = load i32, i32* %15
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %79, i8* %80, i32 %81, i32 %82, i32 %83, i32 %84)
br label %86
86: ; preds = %76, %72
%87 = load i32, i32* %17
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %86
%90 = load i8*, i8** %16
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %90)
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %86
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"Mismatch %d %s: got char %c 0x%x exp char %c 0x%x\0A\00"
@.str.1 = [55 x i8] c"Mismatch %d %s: got optarg %s 0x%x exp optarg %s 0x%x\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [55 x i8] c"Mismatch %d %s: got optind %d 0x%x exp optind %d 0x%x\0A\00"
@.str.4 = [20 x i8] c"FAIL getopttest %s\0A\00"
define void @chkval(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i32 %5, i32 %6, i8* %7) {
%9 = icmp eq i32 %1, %2
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %7, i32 %1, i32 %1, i32 %2, i32 %2)
br label %12
12: ; preds = %10, %8
%13 = icmp eq i8* %3, %4
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = icmp ne i8* %3, null
%16 = icmp ne i8* %4, null
%17 = and i1 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = tail call i32 @strcmp(i8* %3, i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %12
%22 = icmp eq i32 %5, %6
br i1 %22, label %34, label %32
23: ; preds = %14, %18
%24 = select i1 %15, i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%25 = ptrtoint i8* %3 to i64
%26 = trunc i64 %25 to i32
%27 = select i1 %16, i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%28 = ptrtoint i8* %4 to i64
%29 = trunc i64 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %7, i8* %24, i32 %26, i8* %27, i32 %29)
%31 = icmp eq i32 %5, %6
br i1 %31, label %35, label %32
32: ; preds = %23, %21
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %7, i32 %5, i32 %5, i32 %6, i32 %6)
br label %35
34: ; preds = %21
br i1 %9, label %38, label %35
35: ; preds = %23, %32, %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %34
ret void
}