#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*/ memcpy(char *, char const *, int);
int sprintf(char *, char *, int);
int strlen(char const *);
int AddElementAndCount(const char *szElement, int mult, char *szLinearCT,
                       int nLenLinearCT, int *bOverflow) {
  char szMult[16];
  int len1, len2;
  if (mult > 0 && !*bOverflow && 0 < (len1 = strlen(szElement))) {
    if (mult > 1) {
      len2 = sprintf(szMult, "%d", mult);
    } else {
      len2 = 0;
      szMult[0] = '\0';
    }
    if (len1 + len2 < nLenLinearCT) {
      memcpy(szLinearCT, szElement, len1);
      memcpy(szLinearCT + len1, szMult, len2 + 1);
      return len1 + len2;
    } else {
      (*bOverflow)++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<AddElementAndCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1200 <AddElementAndCount+0xd0>
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1200 <AddElementAndCount+0xd0>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    1200 <AddElementAndCount+0xd0>
cmpl   $0x1,-0x14(%rbp)
jle    119e <AddElementAndCount+0x6e>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x48(%rbp)
jmp    11a9 <AddElementAndCount+0x79>
movl   $0x0,-0x48(%rbp)
movb   $0x0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    -0x48(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f0 <AddElementAndCount+0xc0>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x44(%rbp),%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1207 <AddElementAndCount+0xd7>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1200 <AddElementAndCount+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AddElementAndCount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
test   %esi,%esi
jle    114d <AddElementAndCount+0x1d>
mov    %r8,%rbx
cmpl   $0x0,(%r8)
je     115e <AddElementAndCount+0x2e>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    114d <AddElementAndCount+0x1d>
cmp    $0x2,%r13d
jb     1196 <AddElementAndCount+0x66>
lea    0xe80(%rip),%rsi
mov    %rsp,%rdi
mov    %r13d,%edx
mov    %rax,%rbp
call   1050 <sprintf@plt>
mov    %eax,%r13d
mov    %rbp,%rax
jmp    119d <AddElementAndCount+0x6d>
movb   $0x0,(%rsp)
xor    %r13d,%r13d
lea    (%rax,%r13,1),%ebp
cmp    %r12d,%ebp
jge    11cc <AddElementAndCount+0x9c>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %rax,%rbx
call   1040 <memcpy@plt>
mov    %ebx,%edi
add    %r14,%rdi
add    $0x1,%r13d
mov    %rsp,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
jmp    114d <AddElementAndCount+0x1d>
addl   $0x1,(%rbx)
xor    %ebp,%ebp
jmp    114d <AddElementAndCount+0x1d>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @AddElementAndCount(i8* %0, i32 %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca [16 x i8]
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%15 = load i32, i32* %8
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %61
17: ; preds = %5
%18 = load i32*, i32** %11
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %61, label %21
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %13
%24 = icmp slt i32 0, %23
br i1 %24, label %25, label %61
25: ; preds = %21
%26 = load i32, i32* %8
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%30 = load i32, i32* %8
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 %31, i32* %14
br label %34
32: ; preds = %25
store i32 0, i32* %14
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
store i8 0, i8* %33
br label %34
34: ; preds = %32, %28
%35 = load i32, i32* %13
%36 = load i32, i32* %14
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %10
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %34
%41 = load i8*, i8** %9
%42 = load i8*, i8** %7
%43 = load i32, i32* %13
%44 = call i32 @memcpy(i8* %41, i8* %42, i32 %43)
%45 = load i8*, i8** %9
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%50 = load i32, i32* %14
%51 = add nsw i32 %50, 1
%52 = call i32 @memcpy(i8* %48, i8* %49, i32 %51)
%53 = load i32, i32* %13
%54 = load i32, i32* %14
%55 = add nsw i32 %53, %54
store i32 %55, i32* %6
br label %62
56: ; preds = %34
%57 = load i32*, i32** %11
%58 = load i32, i32* %57
%59 = add nsw i32 %58, 1
store i32 %59, i32* %57
br label %60
60: ; preds = %56
br label %61
61: ; preds = %60, %21, %17, %5
store i32 0, i32* %6
br label %62
62: ; preds = %61, %40
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @AddElementAndCount(i8* %0, i32 %1, i8* %2, i32 %3, i32* nocapture %4) {
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %33
9: ; preds = %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %0)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = icmp ugt i32 %1, 1
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %20
19: ; preds = %15
store i8 0, i8* %7
br label %20
20: ; preds = %19, %17
%21 = phi i32 [ %18, %17 ], [ 0, %19 ]
%22 = add nsw i32 %21, %13
%23 = icmp slt i32 %22, %3
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = tail call i32 @memcpy(i8* %2, i8* %0, i32 %13)
%26 = zext i32 %13 to i64
%27 = getelementptr inbounds i8, i8* %2, i64 %26
%28 = add nsw i32 %21, 1
%29 = call i32 @memcpy(i8* %27, i8* %7, i32 %28)
br label %33
30: ; preds = %20
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %33
33: ; preds = %5, %9, %12, %30, %24
%34 = phi i32 [ %22, %24 ], [ 0, %30 ], [ 0, %12 ], [ 0, %9 ], [ 0, %5 ]
ret i32 %34
}