#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
unsigned long string_new(char *);
unsigned long int string_new_with_size(char *str, int len) {
  char buf[65536];
  int i;
  for (i = 0; (i < sizeof(buf)) && (i < len); i++)
    buf[i] = str[i];
  buf[i] = '\0';
  return string_new(buf);
}


x86 assembly (clang, -O0):
<string_new_with_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10014(%rbp)
movslq -0x10014(%rbp),%rcx
xor    %eax,%eax
cmp    $0x10000,%rcx
mov    %al,-0x10015(%rbp)
jae    115a <string_new_with_size+0x4a>
mov    -0x10014(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x10015(%rbp)
mov    -0x10015(%rbp),%al
test   $0x1,%al
jne    116d <string_new_with_size+0x5d>
jmp    119d <string_new_with_size+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x10014(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x10014(%rbp),%rax
mov    %cl,-0x10010(%rbp,%rax,1)
mov    -0x10014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10014(%rbp)
jmp    112c <string_new_with_size+0x1c>
movslq -0x10014(%rbp),%rax
movb   $0x0,-0x10010(%rbp,%rax,1)
lea    -0x10010(%rbp),%rdi
call   1030 <string_new@plt>
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_new_with_size>:
push   %rbx
sub    $0x10000,%rsp
test   %esi,%esi
jle    1153 <string_new_with_size+0x33>
mov    %rdi,%rax
add    $0xffffffff,%esi
cmp    $0xffff,%esi
mov    $0xffff,%ebx
cmovb  %esi,%ebx
add    $0x1,%ebx
mov    %rsp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
jmp    1155 <string_new_with_size+0x35>
xor    %ebx,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rdi
call   1030 <string_new@plt>
add    $0x10000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @string_new_with_size(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [65536 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %6
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 65536
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = load i8*, i8** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 %24
store i8 %22, i8* %25
br label %26
26: ; preds = %17
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %7
29: ; preds = %15
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 %31
store i8 0, i8* %32
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%34 = call i64 @string_new(i8* %33)
ret i64 %34
}

LLVM IR (-O2):
define i64 @string_new_with_size(i8* nocapture %0, i32 %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%8 = add nsw i32 %1, -1
%9 = call i32 @llvm.umin.i32(i32 %8, i32 65535)
%10 = add nuw nsw i32 %9, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %6, %2
%13 = phi i64 [ 0, %2 ], [ %11, %6 ]
%14 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i64 @string_new(i8* %4)
ret i64 %15
}