#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 */
unsigned int strlen(char *);
short compareflags(char *flags, char *checkflags) {
  unsigned int n1 = 0, n2 = 0;
  char *userflags;
  userflags = (flags != NULL ? flags : "3");
  for (n1 = 0; n1 < strlen(userflags); n1++) {
    for (n2 = 0; n2 < strlen(checkflags); n2++) {
      if (*(userflags + n1) == *(checkflags + n2))
        return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<compareflags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <compareflags+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <compareflags+0x46>
lea    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <compareflags+0x46>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jae    11f3 <compareflags+0xe3>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jae    11e0 <compareflags+0xd0>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11cd <compareflags+0xbd>
movw   $0x1,-0x2(%rbp)
jmp    11f9 <compareflags+0xe9>
jmp    11d2 <compareflags+0xc2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1188 <compareflags+0x78>
jmp    11e5 <compareflags+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <compareflags+0x55>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compareflags>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
test   %rdi,%rdi
lea    0xedb(%rip),%r14
cmovne %rdi,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1196 <compareflags+0x86>
xor    %r15d,%r15d
jmp    1153 <compareflags+0x43>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%r15
jae    1196 <compareflags+0x86>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1140 <compareflags+0x30>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%r15,1),%eax
cmp    (%r12,%rbx,1),%al
je     1190 <compareflags+0x80>
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1170 <compareflags+0x60>
jmp    1140 <compareflags+0x30>
mov    $0x1,%ax
jmp    1198 <compareflags+0x88>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"3\00"
define signext i16 @compareflags(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %2, %24
%8 = phi i64 [ %25, %24 ], [ 0, %2 ]
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %4, i64 %8
br label %17
13: ; preds = %17
%14 = tail call i32 @strlen(i8* %1)
%15 = zext i32 %14 to i64
%16 = icmp ult i64 %23, %15
br i1 %16, label %17, label %24
17: ; preds = %11, %13
%18 = phi i64 [ 0, %11 ], [ %23, %13 ]
%19 = load i8, i8* %12
%20 = getelementptr inbounds i8, i8* %1, i64 %18
%21 = load i8, i8* %20
%22 = icmp eq i8 %19, %21
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %29, label %13
24: ; preds = %13, %7
%25 = add nuw nsw i64 %8, 1
%26 = tail call i32 @strlen(i8* %4)
%27 = zext i32 %26 to i64
%28 = icmp ult i64 %25, %27
br i1 %28, label %7, label %29
29: ; preds = %24, %17, %2
%30 = phi i16 [ 0, %2 ], [ 1, %17 ], [ 0, %24 ]
ret i16 %30
}