#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main() {
  unsigned int size;
  printf("Kac adet char boyutunda bellek ayiralim?\n");
  scanf("%u", &size);
  char *p = (char *)malloc(sizeof(char) * size);
  if (p == NULL) {
    printf("Bellek alinamadi!");
    return -1;
  }
  memset(p, 'b', sizeof(char) * size);
  for (int i = 0; i < sizeof(char) * size; i++)
    printf("%d. eleman: %c\n", i, p[i]);
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <main+0x64>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <main+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x62,%esi
call   1050 <memset@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x8(%rbp),%ecx
shl    $0x0,%rcx
cmp    %rcx,%rax
jae    1211 <main+0xc1>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <main+0x82>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe84(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    %rax,%r15
mov    0xc(%rsp),%edx
mov    %rax,%rdi
mov    $0x62,%esi
call   1060 <memset@plt>
cmpl   $0x0,0xc(%rsp)
je     11de <main+0x7e>
lea    0xe5f(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
cmp    %rax,%rbx
jb     11c0 <main+0x60>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11fd <main+0x9d>
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Kac adet char boyutunda bellek ayiralim?\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [18 x i8] c"Bellek alinamadi!\00"
@.str.3 = [16 x i8] c"%d. eleman: %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = zext i32 %7 to i64
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
17: ; preds = %0
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @memset(i8* %18, i8 signext 98, i32 %22)
store i32 0, i32* %4
br label %24
24: ; preds = %40, %17
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = load i32, i32* %2
%28 = zext i32 %27 to i64
%29 = mul i64 1, %28
%30 = icmp ult i64 %26, %29
br i1 %30, label %31, label %43
31: ; preds = %24
%32 = load i32, i32* %4
%33 = load i8*, i8** %3
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %24
43: ; preds = %24
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
store i32 0, i32* %1
br label %46
46: ; preds = %43, %15
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [18 x i8] c"Bellek alinamadi!\00"
@.str.3 = [16 x i8] c"%d. eleman: %c\0A\00"
@str = [41 x i8] c"Kac adet char boyutunda bellek ayiralim?\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %29
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i32 @memset(i8* %7, i8 signext 98, i32 %12)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %18, %11
%17 = call i32 @free(i8* %7)
br label %29
18: ; preds = %11, %18
%19 = phi i64 [ %25, %18 ], [ 0, %11 ]
%20 = getelementptr inbounds i8, i8* %7, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = trunc i64 %19 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %22)
%25 = add nuw nsw i64 %19, 1
%26 = load i32, i32* %1
%27 = zext i32 %26 to i64
%28 = icmp ult i64 %25, %27
br i1 %28, label %18, label %16
29: ; preds = %16, %9
%30 = phi i32 [ -1, %9 ], [ 0, %16 ]
ret i32 %30
}