#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*/ printf(char *, ...);
char *strtok(char *, char *);
int tlv_str2type(char *);
int check_type_args(int argc, char *type_args, char *op_type, int f_dz) {
  char *delim = ",";
  char *tmp = strtok(op_type, delim);
  int i = 0;
  while (tmp != NULL) {
    int tmp_type = tlv_str2type(tmp);
    if (tmp_type == (char)-1) {
      printf("unrecognized type %s\n", tmp);
      return -1;
    } else {
      type_args[i] = tmp_type;
    }
    tmp = strtok(NULL, delim);
    i++;
  }
  if (i != (argc + (f_dz >= 0 ? -1 : 0))) {
    printf("args to option type too large\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_type_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11d7 <check_type_args+0xa7>
mov    -0x30(%rbp),%rdi
call   1050 <tlv_str2type@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    11a8 <check_type_args+0x78>
mov    -0x30(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <check_type_args+0xe8>
mov    -0x38(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <check_type_args+0x39>
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    -0x1c(%rbp),%edi
xor    %edx,%edx
mov    $0xffffffff,%esi
cmp    $0x0,%edi
cmovge %esi,%edx
add    %edx,%ecx
cmp    %ecx,%eax
je     1211 <check_type_args+0xe1>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <check_type_args+0xe8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_type_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rsi,%rbp
mov    %edi,%r13d
lea    0xea5(%rip),%rsi
mov    %rdx,%rdi
call   1050 <strtok@plt>
xor    %r15d,%r15d
mov    $0x0,%r14d
test   %rax,%rax
je     11bd <check_type_args+0x7d>
mov    %rax,%rbx
mov    %r13d,0x4(%rsp)
xor    %r14d,%r14d
lea    0xe7d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <tlv_str2type@plt>
cmp    $0xffffffff,%eax
je     11da <check_type_args+0x9a>
mov    %al,0x0(%rbp,%r14,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
add    $0x1,%r14
test   %rax,%rax
jne    1190 <check_type_args+0x50>
mov    0x4(%rsp),%r13d
sar    $0x1f,%r12d
not    %r12d
add    %r13d,%r12d
cmp    %r12d,%r14d
je     11f1 <check_type_args+0xb1>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
jmp    11eb <check_type_args+0xab>
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [22 x i8] c"unrecognized type %s\0A\00"
@.str.2 = [31 x i8] c"args to option type too large\0A\00"
define i32 @check_type_args(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10
%14 = load i8*, i8** %8
%15 = load i8*, i8** %10
%16 = call i8* @strtok(i8* %14, i8* %15)
store i8* %16, i8** %11
store i32 0, i32* %12
br label %17
17: ; preds = %35, %4
%18 = load i8*, i8** %11
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %40
20: ; preds = %17
%21 = load i8*, i8** %11
%22 = call i32 @tlv_str2type(i8* %21)
store i32 %22, i32* %13
%23 = load i32, i32* %13
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %11
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %5
br label %52
28: ; preds = %20
%29 = load i32, i32* %13
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %7
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %28
%36 = load i8*, i8** %10
%37 = call i8* @strtok(i8* null, i8* %36)
store i8* %37, i8** %11
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %17
40: ; preds = %17
%41 = load i32, i32* %12
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = icmp sge i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 -1, i32 0
%47 = add nsw i32 %42, %46
%48 = icmp ne i32 %41, %47
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %52
51: ; preds = %40
store i32 0, i32* %5
br label %52
52: ; preds = %51, %49, %25
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [22 x i8] c"unrecognized type %s\0A\00"
@str = [30 x i8] c"args to option type too large\00"
define i32 @check_type_args(i32 %0, i8* nocapture writeonly %1, i8* %2, i32 %3) {
%5 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %4, %14
%8 = phi i64 [ %18, %14 ], [ 0, %4 ]
%9 = phi i8* [ %17, %14 ], [ %5, %4 ]
%10 = tail call i32 @tlv_str2type(i8* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %30
14: ; preds = %7
%15 = trunc i32 %10 to i8
%16 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %15, i8* %16
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = add nuw i64 %8, 1
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %7
20: ; preds = %14
%21 = trunc i64 %18 to i32
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ 0, %4 ], [ %21, %20 ]
%24 = ashr i32 %3, 31
%25 = xor i32 %24, -1
%26 = add nsw i32 %25, %0
%27 = icmp eq i32 %23, %26
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %12, %22, %28
%31 = phi i32 [ -1, %28 ], [ 0, %22 ], [ -1, %12 ]
ret i32 %31
}