#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*/ X509;

/* Variables and functions */
int /*<<< orphan*/ Log(int, char *, int);
int /*<<< orphan*/ X509_PURPOSE_SSL_CLIENT;
int X509_check_purpose(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int grid_x509IsCA(X509 *cert) {
  int idret;
  idret = X509_check_purpose(cert, X509_PURPOSE_SSL_CLIENT, 1);
  if (idret == 1)
    return 1;
  else if (idret == 0)
    return 0;
  else {
    Log(1, "Purpose warning code = %d\n", idret);
    return 1;
  }
}


x86 assembly (clang, -O0):
<grid_x509IsCA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1040 <X509_check_purpose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    115c <grid_x509IsCA+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    118d <grid_x509IsCA+0x6d>
cmpl   $0x0,-0x14(%rbp)
jne    1172 <grid_x509IsCA+0x52>
movl   $0x0,-0x4(%rbp)
jmp    118d <grid_x509IsCA+0x6d>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
lea    0xe7f(%rip),%rsi
call   1030 <Log@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_x509IsCA>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1040 <X509_check_purpose@plt>
cmp    $0x1,%eax
je     1159 <grid_x509IsCA+0x39>
test   %eax,%eax
jne    1141 <grid_x509IsCA+0x21>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeb8(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1030 <Log@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@X509_PURPOSE_SSL_CLIENT = global i32 0
@.str = [27 x i8] c"Purpose warning code = %d\0A\00"
define i32 @grid_x509IsCA(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @X509_PURPOSE_SSL_CLIENT
%7 = call i32 @X509_check_purpose(i32* %5, i32 %6, i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %18
11: ; preds = %1
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* %2
br label %18
15: ; preds = %11
%16 = load i32, i32* %4
%17 = call i32 @Log(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 1, i32* %2
br label %18
18: ; preds = %15, %14, %10
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@X509_PURPOSE_SSL_CLIENT = global i32 0
@.str = [27 x i8] c"Purpose warning code = %d\0A\00"
define i32 @grid_x509IsCA(i32* %0) {
%2 = load i32, i32* @X509_PURPOSE_SSL_CLIENT
%3 = tail call i32 @X509_check_purpose(i32* %0, i32 %2, i32 1)
switch i32 %3, label %5 [
i32 1, label %7
i32 0, label %4
]
4: ; preds = %1
br label %7
5: ; preds = %1
%6 = tail call i32 @Log(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %7
7: ; preds = %1, %5, %4
%8 = phi i32 [ 0, %4 ], [ 1, %5 ], [ %3, %1 ]
ret i32 %8
}