#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 */
typedef int /*<<< orphan*/ s;
typedef int /*<<< orphan*/ X509_EXTENSION;
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int /*<<< orphan*/ Log(int, char *, char *);
int /*<<< orphan*/ OBJ_obj2txt(char *, int, int /*<<< orphan*/, int);
scalar_t__ X509_EXTENSION_get_critical(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_EXTENSION_get_object(int /*<<< orphan*/ *);
unsigned long X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
unsigned long X509_V_OK;
int /*<<< orphan*/ *X509_get_ext(int /*<<< orphan*/ *, int);
int X509_get_ext_count(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_supported_extension(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
unsigned long grid_X509_knownCriticalExts(X509 *cert) {
  int i;
  char s[80];
  X509_EXTENSION *ex;
  for (i = 0; i < X509_get_ext_count(cert); ++i) {
    ex = X509_get_ext(cert, i);
    if (X509_EXTENSION_get_critical(ex) && !X509_supported_extension(ex)) {
      OBJ_obj2txt(s, sizeof(s), X509_EXTENSION_get_object(ex), 1);
      Log(3, "Critical extension found: %s", s);
      if (strcmp(s, "1.3.6.1.5.5.7.1.14") == 0)
        return X509_V_OK;
      if (strcmp(s, "1.3.6.1.4.1.3536.1.222") == 0)
        return X509_V_OK;
      return X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
    }
  }
  return X509_V_OK;
}


x86 assembly (clang, -O0):
<grid_X509_knownCriticalExts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <X509_get_ext_count@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
jge    12a8 <grid_X509_knownCriticalExts+0x128>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <X509_get_ext@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   10a0 <X509_EXTENSION_get_critical@plt>
cmp    $0x0,%rax
je     1295 <grid_X509_knownCriticalExts+0x115>
mov    -0x78(%rbp),%rdi
call   1050 <X509_supported_extension@plt>
cmp    $0x0,%eax
jne    1295 <grid_X509_knownCriticalExts+0x115>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rdi
call   1070 <X509_EXTENSION_get_object@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
mov    $0x50,%esi
mov    $0x1,%ecx
call   1080 <OBJ_obj2txt@plt>
lea    -0x70(%rbp),%rdx
mov    $0x3,%edi
lea    0xddd(%rip),%rsi
call   1090 <Log@plt>
lea    -0x70(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1255 <grid_X509_knownCriticalExts+0xd5>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12b6 <grid_X509_knownCriticalExts+0x136>
lea    -0x70(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1282 <grid_X509_knownCriticalExts+0x102>
mov    0x2d82(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12b6 <grid_X509_knownCriticalExts+0x136>
mov    0x2d4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12b6 <grid_X509_knownCriticalExts+0x136>
jmp    129a <grid_X509_knownCriticalExts+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1196 <grid_X509_knownCriticalExts+0x16>
mov    0x2d49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_X509_knownCriticalExts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
call   1040 <X509_get_ext_count@plt>
mov    0x2e5f(%rip),%r15
test   %eax,%eax
jle    1254 <grid_X509_knownCriticalExts+0xd4>
xor    %ebp,%ebp
jmp    11c3 <grid_X509_knownCriticalExts+0x43>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %r14,%rdi
call   1040 <X509_get_ext_count@plt>
cmp    %eax,%ebp
jge    1254 <grid_X509_knownCriticalExts+0xd4>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <X509_get_ext@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <X509_EXTENSION_get_critical@plt>
test   %rax,%rax
je     11b0 <grid_X509_knownCriticalExts+0x30>
mov    %rbx,%rdi
call   1050 <X509_supported_extension@plt>
test   %eax,%eax
jne    11b0 <grid_X509_knownCriticalExts+0x30>
mov    %rbx,%rdi
call   1070 <X509_EXTENSION_get_object@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %eax,%edx
mov    $0x1,%ecx
call   1080 <OBJ_obj2txt@plt>
lea    0xdf1(%rip),%rsi
mov    $0x3,%edi
mov    %rbx,%rdx
call   1090 <Log@plt>
lea    0xdfa(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1254 <grid_X509_knownCriticalExts+0xd4>
lea    0xdf9(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    124d <grid_X509_knownCriticalExts+0xcd>
mov    0x2dad(%rip),%r15
jmp    1254 <grid_X509_knownCriticalExts+0xd4>
mov    0x2d84(%rip),%r15
mov    (%r15),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Critical extension found: %s\00"
@.str.1 = [19 x i8] c"1.3.6.1.5.5.7.1.14\00"
@X509_V_OK = global i64 0
@.str.2 = [23 x i8] c"1.3.6.1.4.1.3536.1.222\00"
@X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = global i64 0
define i64 @grid_X509_knownCriticalExts(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32*
store i32* %0, i32** %3
store i32 0, i32* %4
br label %7
7: ; preds = %44, %1
%8 = load i32, i32* %4
%9 = load i32*, i32** %3
%10 = call i32 @X509_get_ext_count(i32* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %47
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = call i32* @X509_get_ext(i32* %13, i32 %14)
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = call i64 @X509_EXTENSION_get_critical(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %43
19: ; preds = %12
%20 = load i32*, i32** %6
%21 = call i32 @X509_supported_extension(i32* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %43, label %23
23: ; preds = %19
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @X509_EXTENSION_get_object(i32* %25)
%27 = call i32 @OBJ_obj2txt(i8* %24, i32 80, i32 %26, i32 1)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%29 = call i32 @Log(i32 3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i64, i64* @X509_V_OK
store i64 %34, i64* %2
br label %49
35: ; preds = %23
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i64, i64* @X509_V_OK
store i64 %40, i64* %2
br label %49
41: ; preds = %35
%42 = load i64, i64* @X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION
store i64 %42, i64* %2
br label %49
43: ; preds = %19, %12
br label %44
44: ; preds = %43
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %7
47: ; preds = %7
%48 = load i64, i64* @X509_V_OK
store i64 %48, i64* %2
br label %49
49: ; preds = %47, %41, %39, %33
%50 = load i64, i64* %2
ret i64 %50
}

LLVM IR (-O2):
@.str = [29 x i8] c"Critical extension found: %s\00"
@.str.1 = [19 x i8] c"1.3.6.1.5.5.7.1.14\00"
@X509_V_OK = global i64 0
@.str.2 = [23 x i8] c"1.3.6.1.4.1.3536.1.222\00"
@X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = global i64 0
define i64 @grid_X509_knownCriticalExts(i32* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @X509_get_ext_count(i32* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %1, %24
%7 = phi i32 [ %25, %24 ], [ 0, %1 ]
%8 = tail call i32* @X509_get_ext(i32* %0, i32 %7)
%9 = tail call i64 @X509_EXTENSION_get_critical(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %6
%12 = tail call i32 @X509_supported_extension(i32* %8)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = tail call i32 @X509_EXTENSION_get_object(i32* %8)
%16 = call i32 @OBJ_obj2txt(i8* %3, i32 80, i32 %15, i32 1)
%17 = call i32 @Log(i32 3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %3)
%18 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i64* @X509_V_OK, i64* @X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION
br label %28
24: ; preds = %6, %11
%25 = add nuw nsw i32 %7, 1
%26 = tail call i32 @X509_get_ext_count(i32* %0)
%27 = icmp slt i32 %25, %26
br i1 %27, label %6, label %28
28: ; preds = %24, %1, %20, %14
%29 = phi i64* [ @X509_V_OK, %14 ], [ %23, %20 ], [ @X509_V_OK, %1 ], [ @X509_V_OK, %24 ]
%30 = load i64, i64* %29
ret i64 %30
}