#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int *ptr;
  if ((ptr = (int *)malloc(sizeof(int))) == NULL) {
    fprintf(stderr, "Err. line:%d failed memory allocation\n", 41 - 1);
    exit(EXIT_FAILURE);
  }
  *ptr = 1973;
  printf("Value of the integer allocated with malloc(): %d\n", *ptr);
  free(ptr);
  int *ptrn;
  if ((ptrn = (int *)malloc(10 * sizeof(int))) == NULL) {
    fprintf(stderr, "Err. line:%d failed memory allocation\n", 72 - 1);
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 10; i++) {
    ptrn[i] = i;
    printf("%d\n", ptrn[i]);
  }
  free(ptrn);
  int *p;
  p = malloc(sizeof(int));
  if (p != NULL)
    puts("pointer is ok");
  else
    puts("ops, pointer is not good");
  free(p);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b6 <main+0x56>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x28,%edx
call   1060 <fprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
movl   $0x7b5,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x28,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121b <main+0xbb>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x47,%edx
call   1060 <fprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    125f <main+0xff>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1222 <main+0xc2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1292 <main+0x132>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
jmp    129e <main+0x13e>
lea    0xdce(%rip),%rdi
call   1040 <puts@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12a0 <main+0x140>
mov    %rax,%rbx
movl   $0x7b5,(%rax)
lea    0xec0(%rip),%rdi
mov    $0x7b5,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x28,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12b7 <main+0x157>
mov    %rax,%rbx
lea    0xebf(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1050 <printf@plt>
movaps 0xe1f(%rip),%xmm0
movups %xmm0,(%rbx)
mov    %r14,%rdi
mov    $0x3,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x6,%esi
call   1050 <printf@plt>
movaps 0xdf1(%rip),%xmm0
movups %xmm0,0x10(%rbx)
mov    %r14,%rdi
mov    $0x7,%esi
call   1050 <printf@plt>
movl   $0x8,0x20(%rbx)
mov    %r14,%rdi
mov    $0x8,%esi
call   1050 <printf@plt>
movl   $0x9,0x24(%rbx)
mov    %r14,%rdi
mov    $0x9,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xe10(%rip),%rax
lea    0xdfb(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
mov    $0x28,%edx
jmp    12cc <main+0x16c>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    $0x47,%edx
call   1060 <fprintf@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Err. line:%d failed memory allocation\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"Value of the integer allocated with malloc(): %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [14 x i8] c"pointer is ok\00"
@.str.4 = [25 x i8] c"ops, pointer is not good\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @malloc(i32 4)
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 40)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %6
store i32 1973, i32* %18
%19 = load i32*, i32** %6
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %6
%23 = call i32 @free(i32* %22)
%24 = call i32* @malloc(i32 40)
store i32* %24, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 71)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %17
store i32 0, i32* %8
br label %32
32: ; preds = %47, %31
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = load i32, i32* %8
%37 = load i32*, i32** %7
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
%41 = load i32*, i32** %7
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %35
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %32
50: ; preds = %32
%51 = load i32*, i32** %7
%52 = call i32 @free(i32* %51)
%53 = call i32* @malloc(i32 4)
store i32* %53, i32** %9
%54 = load i32*, i32** %9
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %60
58: ; preds = %50
%59 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
%61 = load i32*, i32** %9
%62 = call i32 @free(i32* %61)
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Err. line:%d failed memory allocation\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [50 x i8] c"Value of the integer allocated with malloc(): %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [14 x i8] c"pointer is ok\00"
@.str.4 = [25 x i8] c"ops, pointer is not good\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 4)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 40)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
store i32 1973, i32* %3
%11 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 1973)
%12 = tail call i32 @free(i32* %3)
%13 = tail call i32* @malloc(i32 40)
%14 = icmp eq i32* %13, null
br i1 %14, label %38, label %15
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%19 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %19
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%21 = getelementptr inbounds i32, i32* %13, i64 4
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 5)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 6)
%25 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %25
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 7)
%27 = getelementptr inbounds i32, i32* %13, i64 8
store i32 8, i32* %27
%28 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 8)
%29 = getelementptr inbounds i32, i32* %13, i64 9
store i32 9, i32* %29
%30 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 9)
%31 = tail call i32 @free(i32* %13)
%32 = tail call i32* @malloc(i32 4)
%33 = icmp eq i32* %32, null
%34 = select i1 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0)
%35 = tail call i32 @puts(i8* dereferenceable(1) %34)
%36 = tail call i32 @free(i32* %32)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
38: ; preds = %10
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 71)
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
}