#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 *, int);
int strlen(char *);
int MakeHillFormulaString(char *szHillFormula, char *szLinearCT,
                          int nLen_szLinearCT, int *bOverflow) {
  int nLen;
  if (szHillFormula && !*bOverflow) {
    if (nLen_szLinearCT > (nLen = strlen(szHillFormula))) {
      memcpy(szLinearCT, szHillFormula, nLen + 1);
      return nLen;
    }
    *bOverflow |= 1;
    return nLen_szLinearCT + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<MakeHillFormulaString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a5 <MakeHillFormulaString+0x85>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11a5 <MakeHillFormulaString+0x85>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
mov    %ecx,-0x2c(%rbp)
cmp    %ecx,%eax
jle    118c <MakeHillFormulaString+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <MakeHillFormulaString+0x8c>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <MakeHillFormulaString+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeHillFormulaString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1169 <MakeHillFormulaString+0x49>
mov    %rcx,%rbp
cmpl   $0x0,(%rcx)
jne    1169 <MakeHillFormulaString+0x49>
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    %r12d,%eax
jge    115e <MakeHillFormulaString+0x3e>
mov    %eax,%ebx
mov    %eax,%edx
add    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
jmp    1169 <MakeHillFormulaString+0x49>
orb    $0x1,0x0(%rbp)
add    $0x1,%r12d
mov    %r12d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @MakeHillFormulaString(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %35
13: ; preds = %4
%14 = load i32*, i32** %9
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %13
%18 = load i32, i32* %8
%19 = load i8*, i8** %6
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %10
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i8*, i8** %7
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = add nsw i32 %25, 1
%27 = call i32 @memcpy(i8* %23, i8* %24, i32 %26)
%28 = load i32, i32* %10
store i32 %28, i32* %5
br label %36
29: ; preds = %17
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = or i32 %31, 1
store i32 %32, i32* %30
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %36
35: ; preds = %13, %4
store i32 0, i32* %5
br label %36
36: ; preds = %35, %29, %22
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
define i32 @MakeHillFormulaString(i8* %0, i8* %1, i32 %2, i32* nocapture %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %19, label %6
6: ; preds = %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp slt i32 %10, %2
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = add nsw i32 %10, 1
%14 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %13)
br label %19
15: ; preds = %9
%16 = load i32, i32* %3
%17 = or i32 %16, 1
store i32 %17, i32* %3
%18 = add nsw i32 %2, 1
br label %19
19: ; preds = %4, %6, %15, %12
%20 = phi i32 [ %10, %12 ], [ %18, %15 ], [ 0, %6 ], [ 0, %4 ]
ret i32 %20
}