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

/* Variables and functions */
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, ...);
char *X509_PURPOSE_get0_name(int /*<<< orphan*/ *);
int X509_PURPOSE_get_id(int /*<<< orphan*/ *);
int X509_check_purpose(int /*<<< orphan*/ *, int, int);
int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt) {
  int id, i, idret;
  char *pname;
  id = X509_PURPOSE_get_id(pt);
  pname = X509_PURPOSE_get0_name(pt);
  for (i = 0; i < 2; i++) {
    idret = X509_check_purpose(cert, id, i);
    BIO_printf(bio, "%s%s : ", pname, i ? " CA" : "");
    if (idret == 1)
      BIO_printf(bio, "Yes\n");
    else if (idret == 0)
      BIO_printf(bio, "No\n");
    else
      BIO_printf(bio, "Yes (WARNING code=%d)\n", idret);
  }
  return 1;
}


x86 assembly (clang, -O0):
<purpose_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <X509_PURPOSE_get_id@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <X509_PURPOSE_get0_name@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    122d <purpose_print+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <X509_check_purpose@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%esi
lea    0xe89(%rip),%rcx
lea    0xe5f(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
cmpl   $0x1,-0x24(%rbp)
jne    11df <purpose_print+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    121a <purpose_print+0xda>
cmpl   $0x0,-0x24(%rbp)
jne    1200 <purpose_print+0xc0>
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    1215 <purpose_print+0xd5>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    121a <purpose_print+0xda>
jmp    121f <purpose_print+0xdf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <purpose_print+0x34>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<purpose_print>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <X509_PURPOSE_get_id@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1040 <X509_PURPOSE_get0_name@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %r12d,%esi
xor    %edx,%edx
call   1060 <X509_check_purpose@plt>
mov    %eax,%ebp
lea    0xe83(%rip),%rsi
lea    0xea7(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
test   %ebp,%ebp
je     11a3 <purpose_print+0x63>
cmp    $0x1,%ebp
jne    11b6 <purpose_print+0x76>
lea    0xe6b(%rip),%rsi
jmp    11aa <purpose_print+0x6a>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <BIO_printf@plt>
jmp    11c9 <purpose_print+0x89>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
call   1060 <X509_check_purpose@plt>
mov    %eax,%ebp
lea    0xe1e(%rip),%rsi
lea    0xe1f(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
cmp    $0x1,%ebp
je     1208 <purpose_print+0xc8>
test   %ebp,%ebp
jne    121b <purpose_print+0xdb>
lea    0xe0b(%rip),%rsi
jmp    120f <purpose_print+0xcf>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <BIO_printf@plt>
jmp    122e <purpose_print+0xee>
lea    0xdf3(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s%s : \00"
@.str.1 = [4 x i8] c" CA\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"Yes\0A\00"
@.str.4 = [4 x i8] c"No\0A\00"
@.str.5 = [23 x i8] c"Yes (WARNING code=%d)\0A\00"
define i32 @purpose_print(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%11 = load i32*, i32** %6
%12 = call i32 @X509_PURPOSE_get_id(i32* %11)
store i32 %12, i32* %7
%13 = load i32*, i32** %6
%14 = call i8* @X509_PURPOSE_get0_name(i32* %13)
store i8* %14, i8** %10
store i32 0, i32* %8
br label %15
15: ; preds = %47, %3
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %50
18: ; preds = %15
%19 = load i32*, i32** %5
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = call i32 @X509_check_purpose(i32* %19, i32 %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32*, i32** %4
%24 = load i8*, i8** %10
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%29 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %28)
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %18
%33 = load i32*, i32** %4
%34 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %46
35: ; preds = %18
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32*, i32** %4
%40 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %45
41: ; preds = %35
%42 = load i32*, i32** %4
%43 = load i32, i32* %9
%44 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %38
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %15
50: ; preds = %15
ret i32 1
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s%s : \00"
@.str.1 = [4 x i8] c" CA\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"Yes\0A\00"
@.str.4 = [4 x i8] c"No\0A\00"
@.str.5 = [23 x i8] c"Yes (WARNING code=%d)\0A\00"
define i32 @purpose_print(i32* %0, i32* %1, i32* %2) {
%4 = tail call i32 @X509_PURPOSE_get_id(i32* %2)
%5 = tail call i8* @X509_PURPOSE_get0_name(i32* %2)
%6 = tail call i32 @X509_check_purpose(i32* %1, i32 %4, i32 0)
%7 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
switch i32 %6, label %12 [
i32 1, label %8
i32 0, label %10
]
8: ; preds = %3
%9 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %14
10: ; preds = %3
%11 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %14
12: ; preds = %3
%13 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %6)
br label %14
14: ; preds = %8, %12, %10
%15 = tail call i32 @X509_check_purpose(i32* %1, i32 %4, i32 1)
%16 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
switch i32 %15, label %21 [
i32 1, label %19
i32 0, label %17
]
17: ; preds = %14
%18 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %23
19: ; preds = %14
%20 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %23
21: ; preds = %14
%22 = tail call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %15)
br label %23
23: ; preds = %21, %19, %17
ret i32 1
}