#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*/ strncpy(unsigned char *, unsigned char *, int);
int unicoder_decodeBom(unsigned char *p) {
  int i;
  unsigned int len;
  unsigned char newp[4];
  if (p == NULL)
    return -1;
  for (i = 0; i < 4; i++)
    newp[i] = 0;
  strncpy(newp, p, 4);
  strncpy(newp + 1, p + 1, 3);
  strncpy(newp + 2, p + 2, 2);
  strncpy(newp + 3, p + 3, 1);
  if ((newp[0] == 0x00) && (newp[1] == 0x00) && (newp[2] == 0xfe) &&
      (newp[3] == 0xff))
    return 5;
  if ((newp[0] == 0xff) && (newp[1] == 0xfe) && (newp[2] == 0x00) &&
      (newp[3] == 0x00))
    return 6;
  if ((newp[0] == 0xef) && (newp[1] == 0xbb) && (newp[2] == 0xbf))
    return 2;
  if ((newp[0] == 0xfe) && (newp[1] == 0xff))
    return 3;
  if ((newp[0] == 0xff) && (newp[1] == 0xfe))
    return 4;
  return 1;
}


x86 assembly (clang, -O0):
<unicoder_decodeBom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <unicoder_decodeBom+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    115b <unicoder_decodeBom+0x4b>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x1c(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <unicoder_decodeBom+0x2a>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
add    $0x2,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rsi
add    $0x3,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
movzbl -0x1c(%rbp),%eax
cmp    $0x0,%eax
jne    11ff <unicoder_decodeBom+0xef>
movzbl -0x1b(%rbp),%eax
cmp    $0x0,%eax
jne    11ff <unicoder_decodeBom+0xef>
movzbl -0x1a(%rbp),%eax
cmp    $0xfe,%eax
jne    11ff <unicoder_decodeBom+0xef>
movzbl -0x19(%rbp),%eax
cmp    $0xff,%eax
jne    11ff <unicoder_decodeBom+0xef>
movl   $0x5,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movzbl -0x1c(%rbp),%eax
cmp    $0xff,%eax
jne    1243 <unicoder_decodeBom+0x133>
movzbl -0x1b(%rbp),%eax
cmp    $0xfe,%eax
jne    1243 <unicoder_decodeBom+0x133>
movzbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jne    1243 <unicoder_decodeBom+0x133>
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1243 <unicoder_decodeBom+0x133>
movl   $0x6,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movzbl -0x1c(%rbp),%eax
cmp    $0xef,%eax
jne    127c <unicoder_decodeBom+0x16c>
movzbl -0x1b(%rbp),%eax
cmp    $0xbb,%eax
jne    127c <unicoder_decodeBom+0x16c>
movzbl -0x1a(%rbp),%eax
cmp    $0xbf,%eax
jne    127c <unicoder_decodeBom+0x16c>
movl   $0x2,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movzbl -0x1c(%rbp),%eax
cmp    $0xfe,%eax
jne    12a6 <unicoder_decodeBom+0x196>
movzbl -0x1b(%rbp),%eax
cmp    $0xff,%eax
jne    12a6 <unicoder_decodeBom+0x196>
movl   $0x3,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movzbl -0x1c(%rbp),%eax
cmp    $0xff,%eax
jne    12d0 <unicoder_decodeBom+0x1c0>
movzbl -0x1b(%rbp),%eax
cmp    $0xfe,%eax
jne    12d0 <unicoder_decodeBom+0x1c0>
movl   $0x4,-0x4(%rbp)
jmp    12d7 <unicoder_decodeBom+0x1c7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicoder_decodeBom>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11f6 <unicoder_decodeBom+0xe6>
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    0xd(%rsp),%rdi
lea    0x1(%rbx),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0xe(%rsp),%rdi
lea    0x2(%rbx),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
lea    0xf(%rsp),%rdi
add    $0x3,%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    0xc(%rsp),%r9b
mov    0xd(%rsp),%cl
mov    0xe(%rsp),%dil
mov    0xf(%rsp),%bl
test   %r9b,%r9b
jne    11a2 <unicoder_decodeBom+0x92>
test   %cl,%cl
jne    11a2 <unicoder_decodeBom+0x92>
cmp    $0xfe,%dil
jne    11a2 <unicoder_decodeBom+0x92>
mov    $0x5,%eax
cmp    $0xff,%bl
je     11fb <unicoder_decodeBom+0xeb>
mov    %r9d,%eax
not    %al
mov    %ecx,%edx
xor    $0xfe,%dl
xor    %esi,%esi
or     %al,%dl
sete   %r8b
jne    11c4 <unicoder_decodeBom+0xb4>
test   %dil,%dil
jne    11c4 <unicoder_decodeBom+0xb4>
mov    $0x6,%eax
test   %bl,%bl
je     11fb <unicoder_decodeBom+0xeb>
cmp    $0xef,%r9b
jne    11da <unicoder_decodeBom+0xca>
cmp    $0xbb,%cl
jne    11da <unicoder_decodeBom+0xca>
mov    $0x2,%eax
cmp    $0xbf,%dil
je     11fb <unicoder_decodeBom+0xeb>
xor    $0xfe,%r9b
not    %cl
mov    %r8b,%sil
lea    (%rsi,%rsi,2),%edx
add    $0x1,%edx
or     %r9b,%cl
mov    $0x3,%eax
cmovne %edx,%eax
jmp    11fb <unicoder_decodeBom+0xeb>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @unicoder_decodeBom(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %120
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %18, %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %11
21: ; preds = %11
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%23 = load i8*, i8** %3
%24 = call i32 @strncpy(i8* %22, i8* %23, i32 4)
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @strncpy(i8* %26, i8* %28, i32 3)
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = call i32 @strncpy(i8* %31, i8* %33, i32 2)
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = call i32 @strncpy(i8* %36, i8* %38, i32 1)
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %60
44: ; preds = %21
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %60
49: ; preds = %44
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp eq i32 %52, 254
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 255
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 5, i32* %2
br label %120
60: ; preds = %54, %49, %44, %21
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = icmp eq i32 %63, 255
br i1 %64, label %65, label %81
65: ; preds = %60
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = icmp eq i32 %68, 254
br i1 %69, label %70, label %81
70: ; preds = %65
%71 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %70
%76 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %75
store i32 6, i32* %2
br label %120
81: ; preds = %75, %70, %65, %60
%82 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = icmp eq i32 %84, 239
br i1 %85, label %86, label %97
86: ; preds = %81
%87 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = icmp eq i32 %89, 187
br i1 %90, label %91, label %97
91: ; preds = %86
%92 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = icmp eq i32 %94, 191
br i1 %95, label %96, label %97
96: ; preds = %91
store i32 2, i32* %2
br label %120
97: ; preds = %91, %86, %81
%98 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = icmp eq i32 %100, 254
br i1 %101, label %102, label %108
102: ; preds = %97
%103 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = icmp eq i32 %105, 255
br i1 %106, label %107, label %108
107: ; preds = %102
store i32 3, i32* %2
br label %120
108: ; preds = %102, %97
%109 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = icmp eq i32 %111, 255
br i1 %112, label %113, label %119
113: ; preds = %108
%114 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = icmp eq i32 %116, 254
br i1 %117, label %118, label %119
118: ; preds = %113
store i32 4, i32* %2
br label %120
119: ; preds = %113, %108
store i32 1, i32* %2
br label %120
120: ; preds = %119, %118, %107, %96, %80, %59, %9
%121 = load i32, i32* %2
ret i32 %121
}

LLVM IR (-O2):
define i32 @unicoder_decodeBom(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to [4 x i8]*
%4 = bitcast i32* %2 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %48, label %6
6: ; preds = %1
store i32 0, i32* %2
%7 = call i32 @strncpy(i8* %4, i8* %0, i32 4)
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 3)
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%12 = getelementptr inbounds i8, i8* %0, i64 2
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 2)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 1)
%17 = load i8, i8* %4
%18 = icmp eq i8 %17, 0
%19 = load i8, i8* %8
%20 = icmp eq i8 %19, 0
%21 = select i1 %18, i1 %20, i1 false
%22 = load i8, i8* %11
%23 = icmp eq i8 %22, -2
%24 = select i1 %21, i1 %23, i1 false
%25 = load i8, i8* %14
%26 = icmp eq i8 %25, -1
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %48, label %28
28: ; preds = %6
%29 = icmp eq i8 %17, -1
%30 = icmp eq i8 %19, -2
%31 = select i1 %29, i1 %30, i1 false
%32 = icmp eq i8 %22, 0
%33 = select i1 %31, i1 %32, i1 false
%34 = icmp eq i8 %25, 0
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %48, label %36
36: ; preds = %28
%37 = icmp eq i8 %17, -17
%38 = icmp eq i8 %19, -69
%39 = select i1 %37, i1 %38, i1 false
%40 = icmp eq i8 %22, -65
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %48, label %42
42: ; preds = %36
%43 = icmp eq i8 %17, -2
%44 = icmp eq i8 %19, -1
%45 = select i1 %43, i1 %44, i1 false
%46 = select i1 %31, i32 4, i32 1
%47 = select i1 %45, i32 3, i32 %46
br label %48
48: ; preds = %42, %36, %28, %6, %1
%49 = phi i32 [ -1, %1 ], [ 5, %6 ], [ 6, %28 ], [ 2, %36 ], [ %47, %42 ]
ret i32 %49
}