#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 */
struct pool {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
int pool_new(struct pool *, int);
char *pool_ptr(struct pool *, int);
int pool_new_strn(struct pool *p, const char *str, int len) {
  int h;
  char *b;
  h = pool_new(p, len + 1);
  b = pool_ptr(p, h);
  if (b) {
    memcpy(b, str, len);
    b[len] = 0;
  }
  return h;
}


x86 assembly (clang, -O0):
<pool_new_strn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1050 <pool_new@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <pool_ptr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118c <pool_new_strn+0x5c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pool_new_strn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x1(%r15),%esi
call   1050 <pool_new@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <pool_ptr@plt>
test   %rax,%rax
je     1172 <pool_new_strn+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pool = type { i32 }
define i32 @pool_new_strn(%struct.pool* %0, i8* %1, i32 %2) {
%4 = alloca %struct.pool*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store %struct.pool* %0, %struct.pool** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load %struct.pool*, %struct.pool** %4
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 1
%12 = call i32 @pool_new(%struct.pool* %9, i32 %11)
store i32 %12, i32* %7
%13 = load %struct.pool*, %struct.pool** %4
%14 = load i32, i32* %7
%15 = call i8* @pool_ptr(%struct.pool* %13, i32 %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 @memcpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %8
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %18, %3
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
%struct.pool = type { i32 }
define i32 @pool_new_strn(%struct.pool* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i32 @pool_new(%struct.pool* %0, i32 %4)
%6 = tail call i8* @pool_ptr(%struct.pool* %0, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = tail call i32 @memcpy(i8* %6, i8* %1, i32 %2)
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %8, %3
ret i32 %5
}