#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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int where_in_command_line(int, char **, char *);
int char_set_from_argv(int argc, char **argv, char *tag, char *stoptag,
                       int *found_list, char *destination, int len) {
  int i, which_argc, nguess;
  which_argc = where_in_command_line(argc, argv, tag);
  if (which_argc < 1) {
    fprintf(stderr, "Tag %s not found in char_set_from_argv.\n", tag);
    return -1;
  }
  nguess =
      where_in_command_line(argc - which_argc, &argv[which_argc], stoptag) - 1;
  if (nguess < 0)
    nguess = argc - which_argc;
  found_list[which_argc] = 1;
  for (i = 0; i < nguess; i++) {
    sprintf(destination + i * len * sizeof(char), "%s",
            argv[which_argc + i + 1]);
    found_list[which_argc + i + 1] = 1;
  }
  return nguess;
}


x86 assembly (clang, -O0):
<char_set_from_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <where_in_command_line@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jge    1194 <char_set_from_argv+0x64>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <char_set_from_argv+0x11c>
mov    -0x8(%rbp),%edi
sub    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <where_in_command_line@plt>
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11cb <char_set_from_argv+0x9b>
mov    -0x8(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1246 <char_set_from_argv+0x116>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%eax
imul   0x10(%rbp),%eax
cltq
shl    $0x0,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e1 <char_set_from_argv+0xb1>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_set_from_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r14d
call   1040 <where_in_command_line@plt>
mov    %rax,0x8(%rsp)
test   %eax,%eax
jle    11e0 <char_set_from_argv+0xb0>
mov    0x8(%rsp),%rax
sub    %eax,%r14d
mov    %eax,%r13d
lea    (%r15,%r13,8),%rsi
mov    %r14d,%edi
mov    %r12,%rdx
call   1040 <where_in_command_line@plt>
lea    -0x1(%rax),%r12d
test   %eax,%eax
cmovle %r14d,%r12d
movl   $0x1,0x0(%rbp,%r13,4)
test   %r12d,%r12d
jle    11fe <char_set_from_argv+0xce>
movslq 0x50(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %r15,%r13
lea    0x1(%rax),%r14
add    0x8(%rsp),%eax
movslq %eax,%r15
mov    0x0(%r13,%r15,8),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
movl   $0x1,0x0(%rbp,%r15,4)
add    0x10(%rsp),%rbx
mov    %r14,%rax
cmp    %r14,%r12
jne    11b0 <char_set_from_argv+0x80>
jmp    11fe <char_set_from_argv+0xce>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %r13,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Tag %s not found in char_set_from_argv.\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @char_set_from_argv(i32 %0, i8** %1, i8* %2, i8* %3, i32* %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %9
store i8** %1, i8*** %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i32* %4, i32** %13
store i8* %5, i8** %14
store i32 %6, i32* %15
%19 = load i32, i32* %9
%20 = load i8**, i8*** %10
%21 = load i8*, i8** %11
%22 = call i32 @where_in_command_line(i32 %19, i8** %20, i8* %21)
store i32 %22, i32* %17
%23 = load i32, i32* %17
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %29
25: ; preds = %7
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %11
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 -1, i32* %8
br label %84
29: ; preds = %7
%30 = load i32, i32* %9
%31 = load i32, i32* %17
%32 = sub nsw i32 %30, %31
%33 = load i8**, i8*** %10
%34 = load i32, i32* %17
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %12
%38 = call i32 @where_in_command_line(i32 %32, i8** %36, i8* %37)
%39 = sub nsw i32 %38, 1
store i32 %39, i32* %18
%40 = load i32, i32* %18
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %29
%43 = load i32, i32* %9
%44 = load i32, i32* %17
%45 = sub nsw i32 %43, %44
store i32 %45, i32* %18
br label %46
46: ; preds = %42, %29
%47 = load i32*, i32** %13
%48 = load i32, i32* %17
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 1, i32* %50
store i32 0, i32* %16
br label %51
51: ; preds = %79, %46
%52 = load i32, i32* %16
%53 = load i32, i32* %18
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %82
55: ; preds = %51
%56 = load i8*, i8** %14
%57 = load i32, i32* %16
%58 = load i32, i32* %15
%59 = mul nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = mul i64 %60, 1
%62 = getelementptr inbounds i8, i8* %56, i64 %61
%63 = load i8**, i8*** %10
%64 = load i32, i32* %17
%65 = load i32, i32* %16
%66 = add nsw i32 %64, %65
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %63, i64 %68
%70 = load i8*, i8** %69
%71 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %70)
%72 = load i32*, i32** %13
%73 = load i32, i32* %17
%74 = load i32, i32* %16
%75 = add nsw i32 %73, %74
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %72, i64 %77
store i32 1, i32* %78
br label %79
79: ; preds = %55
%80 = load i32, i32* %16
%81 = add nsw i32 %80, 1
store i32 %81, i32* %16
br label %51
82: ; preds = %51
%83 = load i32, i32* %18
store i32 %83, i32* %8
br label %84
84: ; preds = %82, %25
%85 = load i32, i32* %8
ret i32 %85
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Tag %s not found in char_set_from_argv.\0A\00"
define i32 @char_set_from_argv(i32 %0, i8** %1, i8* %2, i8* %3, i32* nocapture writeonly %4, i8* %5, i32 %6) {
%8 = tail call i32 @where_in_command_line(i32 %0, i8** %1, i8* %2)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %39
13: ; preds = %7
%14 = sub nsw i32 %0, %8
%15 = zext i32 %8 to i64
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = tail call i32 @where_in_command_line(i32 %14, i8** %16, i8* %3)
%18 = add nsw i32 %17, -1
%19 = icmp slt i32 %17, 1
%20 = select i1 %19, i32 %14, i32 %18
%21 = getelementptr inbounds i32, i32* %4, i64 %15
store i32 1, i32* %21
%22 = icmp sgt i32 %20, 0
br i1 %22, label %23, label %39
23: ; preds = %13
%24 = sext i32 %6 to i64
%25 = zext i32 %20 to i64
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ 0, %23 ], [ %30, %26 ]
%28 = mul nsw i64 %27, %24
%29 = getelementptr inbounds i8, i8* %5, i64 %28
%30 = add nuw nsw i64 %27, 1
%31 = trunc i64 %30 to i32
%32 = add i32 %8, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = tail call i8* @strcpy(i8* dereferenceable(1) %29, i8* dereferenceable(1) %35)
%37 = getelementptr inbounds i32, i32* %4, i64 %33
store i32 1, i32* %37
%38 = icmp eq i64 %30, %25
br i1 %38, label %39, label %26
39: ; preds = %26, %13, %10
%40 = phi i32 [ -1, %10 ], [ %20, %13 ], [ %20, %26 ]
ret i32 %40
}