#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, char, size_t const);
int /*<<< orphan*/ printf(char *, unsigned short);
void f1(size_t nchars) {
  char *p = (char *)malloc(nchars);
  const size_t n = nchars + 135147;
  memset(p, 'a', n);
  printf("%c\n", *(p + 100));
  printf("%hu\n", (unsigned short int)*(p + 10000));
}


x86 assembly (clang, -O0):
<f1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20feb,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x61,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
movsbl 0x64(%rax),%eax
lea    0xe88(%rip),%rdi
movzwl %ax,%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movsbl 0x2710(%rax),%eax
lea    0xe72(%rip),%rdi
movzwl %ax,%esi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f1>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <malloc@plt>
mov    %rax,%r14
add    $0x20feb,%rbx
mov    %rax,%rdi
mov    $0x61,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
movsbl 0x64(%r14),%eax
movzwl %ax,%esi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
movsbl 0x2710(%r14),%eax
movzwl %ax,%esi
lea    0xe88(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%c\0A\00"
@.str.1 = [5 x i8] c"%hu\0A\00"
define void @f1(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i64, i64* %2
%9 = add i64 %8, 135147
store i64 %9, i64* %4
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = call i32 @memset(i8* %10, i8 signext 97, i64 %11)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 100
%15 = load i8, i8* %14
%16 = sext i8 %15 to i16
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %16)
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 10000
%20 = load i8, i8* %19
%21 = sext i8 %20 to i16
%22 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %21)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c\0A\00"
@.str.1 = [5 x i8] c"%hu\0A\00"
define void @f1(i64 %0) {
%2 = tail call i64 @malloc(i64 %0)
%3 = inttoptr i64 %2 to i8*
%4 = add i64 %0, 135147
%5 = tail call i32 @memset(i8* %3, i8 signext 97, i64 %4)
%6 = getelementptr inbounds i8, i8* %3, i64 100
%7 = load i8, i8* %6
%8 = sext i8 %7 to i16
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %8)
%10 = getelementptr inbounds i8, i8* %3, i64 10000
%11 = load i8, i8* %10
%12 = sext i8 %11 to i16
%13 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %12)
ret void
}