#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
  unsigned char *data;
};
typedef TYPE_1__ ASN1_STRING;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_STRING_SET;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ memmove(unsigned char *, char const *, int);
unsigned char *realloc(unsigned char *, int);
int strlen(char const *);
int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) {
  const char *data = _data;
  if (len < 0) {
    if (data == NULL)
      return (0);
    else
      len = strlen(data);
  }
  if ((str->length < len) || (str->data == NULL)) {
    unsigned char *tmp;
    tmp = realloc(str->data, len + 1);
    if (tmp == NULL) {
      ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);
      return (0);
    }
    str->data = tmp;
  }
  str->length = len;
  if (data != NULL) {
    memmove(str->data, data, len);
  }
  str->data[str->length] = '\0';
  return (1);
}


x86 assembly (clang, -O0):
<ASN1_STRING_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    118d <ASN1_STRING_set+0x4d>
cmpq   $0x0,-0x28(%rbp)
jne    117c <ASN1_STRING_set+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    123e <ASN1_STRING_set+0xfe>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
jmp    118d <ASN1_STRING_set+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jl     11ab <ASN1_STRING_set+0x6b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11fc <ASN1_STRING_set+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f0 <ASN1_STRING_set+0xb0>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    123e <ASN1_STRING_set+0xfe>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1224 <ASN1_STRING_set+0xe4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_STRING_set>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
test   %edx,%edx
jns    1160 <ASN1_STRING_set+0x20>
test   %r15,%r15
je     11c2 <ASN1_STRING_set+0x82>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
cmp    %ebx,(%r14)
jl     1170 <ASN1_STRING_set+0x30>
test   %rdi,%rdi
jne    1184 <ASN1_STRING_set+0x44>
xor    %edi,%edi
lea    0x1(%rbx),%esi
call   1050 <realloc@plt>
test   %rax,%rax
je     11ab <ASN1_STRING_set+0x6b>
mov    %rax,%rdi
mov    %rax,0x8(%r14)
mov    %ebx,(%r14)
test   %r15,%r15
je     119d <ASN1_STRING_set+0x5d>
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memmove@plt>
mov    0x8(%r14),%rdi
mov    (%r14),%ebx
movslq %ebx,%rax
movb   $0x0,(%rdi,%rax,1)
mov    $0x1,%eax
jmp    11c4 <ASN1_STRING_set+0x84>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8* }
@ASN1_F_ASN1_STRING_SET = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @ASN1_STRING_set(%struct.TYPE_3__* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
store i8* %10, i8** %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %4
br label %71
17: ; preds = %13
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
br label %20
20: ; preds = %17
br label %21
21: ; preds = %20, %3
%22 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 1
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %49
32: ; preds = %27, %21
%33 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
%38 = call i8* @realloc(i8* %35, i32 %37)
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %32
%42 = load i32, i32* @ASN1_F_ASN1_STRING_SET
%43 = load i32, i32* @ERR_R_MALLOC_FAILURE
%44 = call i32 @ASN1err(i32 %42, i32 %43)
store i32 0, i32* %4
br label %71
45: ; preds = %32
%46 = load i8*, i8** %9
%47 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %47, i32 0, i32 1
store i8* %46, i8** %48
br label %49
49: ; preds = %45, %27
%50 = load i32, i32* %7
%51 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %51, i32 0, i32 0
store i32 %50, i32* %52
%53 = load i8*, i8** %8
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %62
55: ; preds = %49
%56 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %56, i32 0, i32 1
%58 = load i8*, i8** %57
%59 = load i8*, i8** %8
%60 = load i32, i32* %7
%61 = call i32 @memmove(i8* %58, i8* %59, i32 %60)
br label %62
62: ; preds = %55, %49
%63 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%64 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %63, i32 0, i32 1
%65 = load i8*, i8** %64
%66 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%67 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %66, i32 0, i32 0
%68 = load i32, i32* %67
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %65, i64 %69
store i8 0, i8* %70
store i32 1, i32* %4
br label %71
71: ; preds = %62, %41, %16
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8* }
@ASN1_F_ASN1_STRING_SET = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @ASN1_STRING_set(%struct.TYPE_3__* nocapture %0, i8* %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = icmp eq i8* %1, null
br i1 %6, label %42, label %7
7: ; preds = %5
%8 = tail call i32 @strlen(i8* %1)
br label %9
9: ; preds = %7, %3
%10 = phi i32 [ %8, %7 ], [ %2, %3 ]
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, %10
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%15 = load i8*, i8** %14
br i1 %13, label %18, label %16
16: ; preds = %9
%17 = icmp eq i8* %15, null
br i1 %17, label %18, label %29
18: ; preds = %9, %16
%19 = phi i8* [ null, %16 ], [ %15, %9 ]
%20 = add nsw i32 %10, 1
%21 = tail call i8* @realloc(i8* %19, i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @ASN1_F_ASN1_STRING_SET
%25 = load i32, i32* @ERR_R_MALLOC_FAILURE
%26 = tail call i32 @ASN1err(i32 %24, i32 %25)
br label %42
27: ; preds = %18
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
store i8* %21, i8** %28
br label %29
29: ; preds = %27, %16
%30 = phi i8* [ %21, %27 ], [ %15, %16 ]
store i32 %10, i32* %11
%31 = icmp eq i8* %1, null
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%34 = tail call i32 @memmove(i8* %30, i8* %1, i32 %10)
%35 = load i8*, i8** %33
%36 = load i32, i32* %11
br label %37
37: ; preds = %32, %29
%38 = phi i32 [ %36, %32 ], [ %10, %29 ]
%39 = phi i8* [ %35, %32 ], [ %30, %29 ]
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %23, %5, %37
%43 = phi i32 [ 1, %37 ], [ 0, %5 ], [ 0, %23 ]
ret i32 %43
}