#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 */
scalar_t__ patterntest(unsigned char *, char const *, int, int /*<<< orphan*/,
                       int);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int chk_id_offset(unsigned char *buf, int bufsize, const char *patterns[],
                  int offset, char *pre) {
  int i;
  for (i = 0; patterns[i]; i = i + 2) {
    if (patterntest(buf, patterns[i], offset, strlen(patterns[i]), bufsize)) {
      strcpy(pre, patterns[i + 1]);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<chk_id_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ec <chk_id_offset+0xbc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    %eax,%ecx
mov    -0x14(%rbp),%r8d
call   1050 <patterntest@plt>
cmp    $0x0,%rax
je     11d9 <chk_id_offset+0xa9>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <chk_id_offset+0xc3>
jmp    11de <chk_id_offset+0xae>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    1151 <chk_id_offset+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_id_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdx),%rbx
test   %rbx,%rbx
je     118e <chk_id_offset+0x5e>
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%rbp
mov    %r8,(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %eax,%ecx
mov    %r13d,%r8d
call   1050 <patterntest@plt>
test   %rax,%rax
jne    1192 <chk_id_offset+0x62>
mov    0x10(%r15,%r14,8),%rbx
add    $0x2,%r14
test   %rbx,%rbx
jne    1160 <chk_id_offset+0x30>
xor    %eax,%eax
jmp    11af <chk_id_offset+0x7f>
mov    %r14d,%eax
shl    $0x3,%rax
or     $0x8,%rax
mov    (%r15,%rax,1),%rsi
mov    (%rsp),%rdi
call   1030 <strcpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @chk_id_offset(i8* %0, i32 %1, i8** nocapture %2, i32 %3, i8* %4) {
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %25, label %8
8: ; preds = %5, %20
%9 = phi i64 [ %21, %20 ], [ 0, %5 ]
%10 = phi i8* [ %23, %20 ], [ %6, %5 ]
%11 = tail call i32 @strlen(i8* %10)
%12 = tail call i64 @patterntest(i8* %0, i8* %10, i32 %3, i32 %11, i32 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = and i64 %9, 4294967294
%16 = or i64 %15, 1
%17 = getelementptr inbounds i8*, i8** %2, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @strcpy(i8* %4, i8* %18)
br label %25
20: ; preds = %8
%21 = add nuw i64 %9, 2
%22 = getelementptr inbounds i8*, i8** %2, i64 %21
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %8
25: ; preds = %20, %5, %14
%26 = phi i32 [ 1, %14 ], [ 0, %5 ], [ 0, %20 ]
ret i32 %26
}