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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *SeqUtil_addRes(char *seq, int length, char res) {
  int seqlen = strlen(seq);
  char *chP;
  int i;
  if (length == -1)
    return seq;
  if ((seq = (char *)realloc(seq, (seqlen + 1 + length) * sizeof(char))) ==
      NULL) {
    fprintf(
        stderr,
        "ERROR: Failed reallocating sequence string for length %d pointer %p\n",
        seqlen + 1 + length, seq);
    exit(1);
  }
  chP = &(seq[seqlen]);
  for (i = seqlen; i < seqlen + length; i++) {
    *chP = res;
    chP++;
  }
  *chP = '\0';
  return seq;
}


x86 assembly (clang, -O0):
<SeqUtil_addRes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1177 <SeqUtil_addRes+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1223 <SeqUtil_addRes+0xe3>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    -0x14(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cb <SeqUtil_addRes+0x8b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
add    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1214 <SeqUtil_addRes+0xd4>
mov    -0x15(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e0 <SeqUtil_addRes+0xa0>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SeqUtil_addRes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
call   1030 <strlen@plt>
cmp    $0xffffffff,%ebx
je     11bc <SeqUtil_addRes+0x6c>
mov    %eax,%ebp
lea    (%rbx,%rbp,1),%r12d
add    $0x1,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1060 <realloc@plt>
test   %rax,%rax
je     11c8 <SeqUtil_addRes+0x78>
mov    %rax,%r15
movslq %ebp,%r12
lea    (%rax,%r12,1),%rdi
test   %ebx,%ebx
jle    11b9 <SeqUtil_addRes+0x69>
add    %r12d,%ebx
lea    0x1(%rbp),%eax
cmp    %eax,%ebx
cmovle %eax,%ebx
not    %ebp
add    %ebx,%ebp
lea    0x1(%rbp),%rdx
movzbl %r14b,%esi
call   1040 <memset@plt>
add    %rbp,%r12
lea    (%r15,%r12,1),%rdi
add    $0x1,%rdi
movb   $0x0,(%rdi)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [69 x i8] c"ERROR: Failed reallocating sequence string for length %d pointer %p\0A\00"
define i8* @SeqUtil_addRes(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i8*, i8** %5
store i8* %16, i8** %4
br label %61
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
%21 = load i32, i32* %6
%22 = add nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i64 @realloc(i8* %18, i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %6
%34 = add nsw i32 %32, %33
%35 = load i8*, i8** %5
%36 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %34, i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %17
%39 = load i8*, i8** %5
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8* %42, i8** %9
%43 = load i32, i32* %8
store i32 %43, i32* %10
br label %44
44: ; preds = %55, %38
%45 = load i32, i32* %10
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = add nsw i32 %46, %47
%49 = icmp slt i32 %45, %48
br i1 %49, label %50, label %58
50: ; preds = %44
%51 = load i8, i8* %7
%52 = load i8*, i8** %9
store i8 %51, i8* %52
%53 = load i8*, i8** %9
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %9
br label %55
55: ; preds = %50
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %44
58: ; preds = %44
%59 = load i8*, i8** %9
store i8 0, i8* %59
%60 = load i8*, i8** %5
store i8* %60, i8** %4
br label %61
61: ; preds = %58, %15
%62 = load i8*, i8** %4
ret i8* %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [69 x i8] c"ERROR: Failed reallocating sequence string for length %d pointer %p\0A\00"
define i8* @SeqUtil_addRes(i8* %0, i32 %1, i8 signext %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %1, -1
br i1 %5, label %32, label %6
6: ; preds = %3
%7 = add i32 %4, %1
%8 = add i32 %7, 1
%9 = tail call i64 @realloc(i8* %0, i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %8, i8* null)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = sext i32 %4 to i64
%18 = getelementptr i8, i8* %10, i64 %17
%19 = icmp sgt i32 %1, 0
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = add i32 %4, 1
%22 = call i32 @llvm.smax.i32(i32 %7, i32 %21)
%23 = xor i32 %4, -1
%24 = add i32 %22, %23
%25 = zext i32 %24 to i64
%26 = add nuw nsw i64 %25, 1
%27 = add nsw i64 %17, %25
%28 = add nsw i64 %27, 1
%29 = getelementptr i8, i8* %10, i64 %28
br label %30
30: ; preds = %20, %16
%31 = phi i8* [ %18, %16 ], [ %29, %20 ]
store i8 0, i8* %31
br label %32
32: ; preds = %3, %30
%33 = phi i8* [ %10, %30 ], [ %0, %3 ]
ret i8* %33
}