#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*/ argError(void *, char const *, int, char const *);
scalar_t__ memcmp(char const *, char const *, int);
int strlen(char const *);
int testArgSelectX(void *aData, const char *zType, int sz, const char *zArg,
                   int *piOut) {
  struct Entry {
    const char *zName;
  };
  struct Entry *pEntry;
  int nArg = strlen(zArg);
  int i = 0;
  int iOut = -1;
  int nOut = 0;
  for (pEntry = (struct Entry *)aData; pEntry->zName;
       pEntry = (struct Entry *)&((unsigned char *)pEntry)[sz]) {
    int nName = strlen(pEntry->zName);
    if (nArg <= nName && memcmp(pEntry->zName, zArg, nArg) == 0) {
      iOut = i;
      if (nName == nArg) {
        nOut = 1;
        break;
      }
      nOut++;
    }
    i++;
  }
  if (nOut != 1) {
    argError(aData, zType, sz, zArg);
  } else {
    *piOut = iOut;
  }
  return (nOut != 1);
}


x86 assembly (clang, -O0):
<testArgSelectX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     11fe <testArgSelectX+0xce>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     11e1 <testArgSelectX+0xb1>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11e1 <testArgSelectX+0xb1>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    11d8 <testArgSelectX+0xa8>
movl   $0x1,-0x40(%rbp)
jmp    11fe <testArgSelectX+0xce>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1174 <testArgSelectX+0x44>
cmpl   $0x1,-0x40(%rbp)
je     1221 <testArgSelectX+0xf1>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1050 <argError@plt>
jmp    122a <testArgSelectX+0xfa>
mov    -0x3c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x40(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testArgSelectX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rcx,%rdi
call   1030 <strlen@plt>
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     11fa <testArgSelectX+0xca>
mov    %eax,%ebp
mov    %r12,0x20(%rsp)
mov    %r14,0x10(%rsp)
mov    %r15d,0xc(%rsp)
movslq %r15d,%r12
movl   $0xffffffff,0x4(%rsp)
ff
movl   $0x0,0x8(%rsp)
mov    %r13,0x18(%rsp)
mov    %r13,%r15
xor    %r13d,%r13d
jmp    11b0 <testArgSelectX+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13d
mov    (%r15,%r12,1),%rdi
add    %r12,%r15
test   %rdi,%rdi
je     11df <testArgSelectX+0xaf>
call   1030 <strlen@plt>
cmp    %eax,%ebp
jg     11a0 <testArgSelectX+0x70>
mov    %eax,%r14d
mov    (%r15),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11a0 <testArgSelectX+0x70>
cmp    %ebp,%r14d
je     1212 <testArgSelectX+0xe2>
addl   $0x1,0x8(%rsp)
mov    %r13d,0x4(%rsp)
jmp    11a0 <testArgSelectX+0x70>
cmpl   $0x1,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0xc(%rsp),%r15d
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%r13
je     121c <testArgSelectX+0xec>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1050 <argError@plt>
mov    $0x1,%eax
jmp    1224 <testArgSelectX+0xf4>
mov    %r13d,0x4(%rsp)
mov    0x10(%rsp),%rax
mov    0x4(%rsp),%ecx
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Entry = type { i8* }
define i32 @testArgSelectX(i8* %0, i8* %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca %struct.Entry*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32* %4, i32** %10
%17 = load i8*, i8** %9
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %12
store i32 0, i32* %13
store i32 -1, i32* %14
store i32 0, i32* %15
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to %struct.Entry*
store %struct.Entry* %20, %struct.Entry** %11
br label %21
21: ; preds = %54, %5
%22 = load %struct.Entry*, %struct.Entry** %11
%23 = getelementptr inbounds %struct.Entry, %struct.Entry* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %61
26: ; preds = %21
%27 = load %struct.Entry*, %struct.Entry** %11
%28 = getelementptr inbounds %struct.Entry, %struct.Entry* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %16
%31 = load i32, i32* %12
%32 = load i32, i32* %16
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %51
34: ; preds = %26
%35 = load %struct.Entry*, %struct.Entry** %11
%36 = getelementptr inbounds %struct.Entry, %struct.Entry* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = load i8*, i8** %9
%39 = load i32, i32* %12
%40 = call i64 @memcmp(i8* %37, i8* %38, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %34
%43 = load i32, i32* %13
store i32 %43, i32* %14
%44 = load i32, i32* %16
%45 = load i32, i32* %12
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 1, i32* %15
br label %61
48: ; preds = %42
%49 = load i32, i32* %15
%50 = add nsw i32 %49, 1
store i32 %50, i32* %15
br label %51
51: ; preds = %48, %34, %26
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %54
54: ; preds = %51
%55 = load %struct.Entry*, %struct.Entry** %11
%56 = bitcast %struct.Entry* %55 to i8*
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = bitcast i8* %59 to %struct.Entry*
store %struct.Entry* %60, %struct.Entry** %11
br label %21
61: ; preds = %47, %21
%62 = load i32, i32* %15
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i8*, i8** %6
%66 = load i8*, i8** %7
%67 = load i32, i32* %8
%68 = load i8*, i8** %9
%69 = call i32 @argError(i8* %65, i8* %66, i32 %67, i8* %68)
br label %73
70: ; preds = %61
%71 = load i32, i32* %14
%72 = load i32*, i32** %10
store i32 %71, i32* %72
br label %73
73: ; preds = %70, %64
%74 = load i32, i32* %15
%75 = icmp ne i32 %74, 1
%76 = zext i1 %75 to i32
ret i32 %76
}

LLVM IR (-O2):
define i32 @testArgSelectX(i8* %0, i8* %1, i32 %2, i8* %3, i32* nocapture writeonly %4) {
%6 = tail call i32 @strlen(i8* %3)
%7 = bitcast i8* %0 to i8**
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %39, label %10
10: ; preds = %5
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %10, %29
%13 = phi i8* [ %8, %10 ], [ %35, %29 ]
%14 = phi i8** [ %7, %10 ], [ %34, %29 ]
%15 = phi i32 [ 0, %10 ], [ %31, %29 ]
%16 = phi i32 [ -1, %10 ], [ %30, %29 ]
%17 = phi i32 [ 0, %10 ], [ %32, %29 ]
%18 = bitcast i8** %14 to i8*
%19 = tail call i32 @strlen(i8* %13)
%20 = icmp sgt i32 %6, %19
br i1 %20, label %29, label %21
21: ; preds = %12
%22 = load i8*, i8** %14
%23 = tail call i64 @memcmp(i8* %22, i8* %3, i32 %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = icmp eq i32 %19, %6
br i1 %26, label %41, label %27
27: ; preds = %25
%28 = add nsw i32 %15, 1
br label %29
29: ; preds = %12, %21, %27
%30 = phi i32 [ %17, %27 ], [ %16, %21 ], [ %16, %12 ]
%31 = phi i32 [ %28, %27 ], [ %15, %21 ], [ %15, %12 ]
%32 = add nuw nsw i32 %17, 1
%33 = getelementptr inbounds i8, i8* %18, i64 %11
%34 = bitcast i8* %33 to i8**
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %12
37: ; preds = %29
%38 = icmp eq i32 %31, 1
br i1 %38, label %41, label %39
39: ; preds = %5, %37
%40 = tail call i32 @argError(i8* %0, i8* %1, i32 %2, i8* %3)
br label %43
41: ; preds = %25, %37
%42 = phi i32 [ %30, %37 ], [ %17, %25 ]
store i32 %42, i32* %4
br label %43
43: ; preds = %41, %39
%44 = phi i32 [ 0, %41 ], [ 1, %39 ]
ret i32 %44
}