#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ data;
};
typedef int /*<<< orphan*/ CONF;
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ ASN1_TYPE;

/* Variables and functions */
int /*<<< orphan*/ ASN1_TYPE_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_generate_nconf(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ BUF_MEM_grow(TYPE_1__ *, int);
int /*<<< orphan*/ NCONF_free(int /*<<< orphan*/ *);
char *NCONF_get_string(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ NCONF_load(int /*<<< orphan*/ *, char *, long *);
int /*<<< orphan*/ *NCONF_new(int /*<<< orphan*/ *);
int i2d_ASN1_TYPE(int /*<<< orphan*/ *, unsigned char **);
int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf) {
  CONF *cnf = NULL;
  int len;
  long errline;
  unsigned char *p;
  ASN1_TYPE *atyp = NULL;
  if (genconf) {
    cnf = NCONF_new(NULL);
    if (!NCONF_load(cnf, genconf, &errline))
      goto conferr;
    if (!genstr)
      genstr = NCONF_get_string(cnf, "default", "asn1");
    if (!genstr) {
      BIO_printf(bio, "Can't find 'asn1' in '%s'\n", genconf);
      goto err;
    }
  }
  atyp = ASN1_generate_nconf(genstr, cnf);
  NCONF_free(cnf);
  if (!atyp)
    return -1;
  len = i2d_ASN1_TYPE(atyp, NULL);
  if (len <= 0)
    goto err;
  if (!BUF_MEM_grow(buf, len))
    goto err;
  p = (unsigned char *)buf->data;
  i2d_ASN1_TYPE(atyp, &p);
  ASN1_TYPE_free(atyp);
  return len;
conferr:
  if (errline > 0)
    BIO_printf(bio, "Error on line %ld of config file '%s'\n", errline,
               genconf);
  else
    BIO_printf(bio, "Error loading config file '%s'\n", genconf);
err:
  NCONF_free(cnf);
  ASN1_TYPE_free(atyp);
  return -1;
}


x86 assembly (clang, -O0):
<do_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1240 <do_generate+0xb0>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <NCONF_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1090 <NCONF_load@plt>
cmp    $0x0,%eax
jne    11ef <do_generate+0x5f>
jmp    12d6 <do_generate+0x146>
cmpq   $0x0,-0x18(%rbp)
jne    1215 <do_generate+0x85>
mov    -0x30(%rbp),%rdi
lea    0xdfb(%rip),%rsi
lea    0xdfc(%rip),%rdx
call   1060 <NCONF_get_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123b <do_generate+0xab>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    131b <do_generate+0x18b>
jmp    1240 <do_generate+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <ASN1_generate_nconf@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <NCONF_free@plt>
cmpq   $0x0,-0x50(%rbp)
jne    1271 <do_generate+0xe1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1334 <do_generate+0x1a4>
mov    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <i2d_ASN1_TYPE@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     1290 <do_generate+0x100>
jmp    131b <do_generate+0x18b>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <BUF_MEM_grow@plt>
cmp    $0x0,%eax
jne    12aa <do_generate+0x11a>
jmp    131b <do_generate+0x18b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1080 <i2d_ASN1_TYPE@plt>
mov    -0x50(%rbp),%rdi
call   1070 <ASN1_TYPE_free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1334 <do_generate+0x1a4>
cmpq   $0x0,-0x40(%rbp)
jle    1300 <do_generate+0x170>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    1316 <do_generate+0x186>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1050 <BIO_printf@plt>
jmp    131b <do_generate+0x18b>
mov    -0x30(%rbp),%rdi
call   10b0 <NCONF_free@plt>
mov    -0x50(%rbp),%rdi
call   1070 <ASN1_TYPE_free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_generate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rsi,%rbx
test   %rdx,%rdx
je     11fa <do_generate+0x6a>
mov    %rdx,%rbp
mov    %rdi,%r13
xor    %edi,%edi
call   1040 <NCONF_new@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1090 <NCONF_load@plt>
test   %eax,%eax
je     1259 <do_generate+0xc9>
test   %rbx,%rbx
jne    11fd <do_generate+0x6d>
lea    0xe23(%rip),%rsi
lea    0xe24(%rip),%rdx
mov    %r15,%rdi
call   1060 <NCONF_get_string@plt>
test   %rax,%rax
je     1285 <do_generate+0xf5>
mov    %rax,%rbx
jmp    11fd <do_generate+0x6d>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <ASN1_generate_nconf@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   10b0 <NCONF_free@plt>
test   %r12,%r12
je     12ac <do_generate+0x11c>
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <i2d_ASN1_TYPE@plt>
test   %eax,%eax
jle    129c <do_generate+0x10c>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <BUF_MEM_grow@plt>
test   %eax,%eax
je     129c <do_generate+0x10c>
mov    (%r14),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1080 <i2d_ASN1_TYPE@plt>
mov    %r12,%rdi
call   1070 <ASN1_TYPE_free@plt>
jmp    12b1 <do_generate+0x121>
mov    0x10(%rsp),%rdx
test   %rdx,%rdx
jle    127c <do_generate+0xec>
lea    0xdbe(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdi
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
jmp    129c <do_generate+0x10c>
lea    0xdcc(%rip),%rsi
jmp    128c <do_generate+0xfc>
lea    0xd81(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <BIO_printf@plt>
mov    %r15,%rdi
call   10b0 <NCONF_free@plt>
mov    %r12,%rdi
call   1070 <ASN1_TYPE_free@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64 }
@.str = [8 x i8] c"default\00"
@.str.1 = [5 x i8] c"asn1\00"
@.str.2 = [27 x i8] c"Can't find 'asn1' in '%s'\0A\00"
@.str.3 = [39 x i8] c"Error on line %ld of config file '%s'\0A\00"
@.str.4 = [32 x i8] c"Error loading config file '%s'\0A\00"
define i32 @do_generate(i32* %0, i8* %1, i8* %2, %struct.TYPE_4__* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.TYPE_4__*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i32*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store %struct.TYPE_4__* %3, %struct.TYPE_4__** %9
store i32* null, i32** %10
store i32* null, i32** %14
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %38
17: ; preds = %4
%18 = call i32* @NCONF_new(i32* null)
store i32* %18, i32** %10
%19 = load i32*, i32** %10
%20 = load i8*, i8** %8
%21 = call i32 @NCONF_load(i32* %19, i8* %20, i64* %12)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
br label %69
24: ; preds = %17
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32*, i32** %10
%29 = call i8* @NCONF_get_string(i32* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %7
br label %30
30: ; preds = %27, %24
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i32*, i32** %6
%35 = load i8*, i8** %8
%36 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %82
37: ; preds = %30
br label %38
38: ; preds = %37, %4
%39 = load i8*, i8** %7
%40 = load i32*, i32** %10
%41 = call i32* @ASN1_generate_nconf(i8* %39, i32* %40)
store i32* %41, i32** %14
%42 = load i32*, i32** %10
%43 = call i32 @NCONF_free(i32* %42)
%44 = load i32*, i32** %14
%45 = icmp ne i32* %44, null
br i1 %45, label %47, label %46
46: ; preds = %38
store i32 -1, i32* %5
br label %87
47: ; preds = %38
%48 = load i32*, i32** %14
%49 = call i32 @i2d_ASN1_TYPE(i32* %48, i8** null)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = icmp sle i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %47
br label %82
53: ; preds = %47
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%55 = load i32, i32* %11
%56 = call i32 @BUF_MEM_grow(%struct.TYPE_4__* %54, i32 %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %53
br label %82
59: ; preds = %53
%60 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to i8*
store i8* %63, i8** %13
%64 = load i32*, i32** %14
%65 = call i32 @i2d_ASN1_TYPE(i32* %64, i8** %13)
%66 = load i32*, i32** %14
%67 = call i32 @ASN1_TYPE_free(i32* %66)
%68 = load i32, i32* %11
store i32 %68, i32* %5
br label %87
69: ; preds = %23
%70 = load i64, i64* %12
%71 = icmp sgt i64 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %69
%73 = load i32*, i32** %6
%74 = load i64, i64* %12
%75 = load i8*, i8** %8
%76 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %73, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 %74, i8* %75)
br label %81
77: ; preds = %69
%78 = load i32*, i32** %6
%79 = load i8*, i8** %8
%80 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %78, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %77, %72
br label %82
82: ; preds = %81, %58, %52, %33
%83 = load i32*, i32** %10
%84 = call i32 @NCONF_free(i32* %83)
%85 = load i32*, i32** %14
%86 = call i32 @ASN1_TYPE_free(i32* %85)
store i32 -1, i32* %5
br label %87
87: ; preds = %82, %59, %46
%88 = load i32, i32* %5
ret i32 %88
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64 }
@.str = [8 x i8] c"default\00"
@.str.1 = [5 x i8] c"asn1\00"
@.str.2 = [27 x i8] c"Can't find 'asn1' in '%s'\0A\00"
@.str.3 = [39 x i8] c"Error on line %ld of config file '%s'\0A\00"
@.str.4 = [32 x i8] c"Error loading config file '%s'\0A\00"
define i32 @do_generate(i32* %0, i8* %1, i8* %2, %struct.TYPE_4__* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = bitcast i64* %5 to i8*
%8 = bitcast i8** %6 to i8*
%9 = icmp eq i8* %2, null
br i1 %9, label %21, label %10
10: ; preds = %4
%11 = tail call i32* @NCONF_new(i32* null)
%12 = call i32 @NCONF_load(i32* %11, i8* %2, i64* %5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %10
%15 = icmp eq i8* %1, null
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = call i8* @NCONF_get_string(i32* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %46
21: ; preds = %14, %16, %4
%22 = phi i8* [ %17, %16 ], [ %1, %4 ], [ %1, %14 ]
%23 = phi i32* [ %11, %16 ], [ null, %4 ], [ %11, %14 ]
%24 = call i32* @ASN1_generate_nconf(i8* %22, i32* %23)
%25 = call i32 @NCONF_free(i32* %23)
%26 = icmp eq i32* %24, null
br i1 %26, label %51, label %27
27: ; preds = %21
%28 = call i32 @i2d_ASN1_TYPE(i32* %24, i8** null)
%29 = icmp slt i32 %28, 1
br i1 %29, label %46, label %30
30: ; preds = %27
%31 = call i32 @BUF_MEM_grow(%struct.TYPE_4__* %3, i32 %28)
%32 = icmp eq i32 %31, 0
br i1 %32, label %46, label %33
33: ; preds = %30
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%35 = load i64, i64* %34
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %6
%37 = call i32 @i2d_ASN1_TYPE(i32* %24, i8** %6)
%38 = call i32 @ASN1_TYPE_free(i32* %24)
br label %51
39: ; preds = %10
%40 = load i64, i64* %5
%41 = icmp sgt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 %40, i8* %2)
br label %46
44: ; preds = %39
%45 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %46
46: ; preds = %42, %44, %30, %27, %19
%47 = phi i32* [ %23, %27 ], [ %23, %30 ], [ %11, %19 ], [ %11, %42 ], [ %11, %44 ]
%48 = phi i32* [ %24, %27 ], [ %24, %30 ], [ null, %19 ], [ null, %42 ], [ null, %44 ]
%49 = call i32 @NCONF_free(i32* %47)
%50 = call i32 @ASN1_TYPE_free(i32* %48)
br label %51
51: ; preds = %21, %46, %33
%52 = phi i32 [ -1, %46 ], [ %28, %33 ], [ -1, %21 ]
ret i32 %52
}