#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(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void one() {
  char *ptr = NULL;
  char *buflist = NULL;
  buflist = (char *)malloc(1024);
  ptr = (char *)(*((unsigned long *)buflist));
  printf("----------------------------------\n");
  if (ptr == NULL) {
    printf("error");
    exit(1);
  } else {
    printf("ptr != NULL");
  }
  for (int i = 0; i < 5; ++i) {
    ptr[i] = (char)i;
  }
  for (int i = 0; i < 5; ++i) {
    printf("%d\n", *(ptr++));
  }
}


x86 assembly (clang, -O0):
<one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1192 <one+0x62>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11cf <one+0x9f>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <one+0x77>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    120e <one+0xde>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d6 <one+0xa6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<one>:
push   %r14
push   %rbx
push   %rax
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    (%rax),%rbx
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
test   %rbx,%rbx
je     11cc <one+0x8c>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x3020100,(%rbx)
movb   $0x4,0x4(%rbx)
lea    0xe91(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x1(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x2(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x3(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"----------------------------------\0A\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [12 x i8] c"ptr != NULL\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define void @one() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* null, i8** %1
store i8* null, i8** %2
%5 = call i64 @malloc(i32 1024)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i64*
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %1
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17
store i32 0, i32* %3
br label %20
20: ; preds = %30, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 5
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %1
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %23
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %20
33: ; preds = %20
store i32 0, i32* %4
br label %34
34: ; preds = %43, %33
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 5
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** %1
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %1
%40 = load i8, i8* %38
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %34
46: ; preds = %34
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [12 x i8] c"ptr != NULL\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [35 x i8] c"----------------------------------\00"
define void @one() {
%1 = tail call i64 @malloc(i32 1024)
%2 = inttoptr i64 %1 to i64*
%3 = load i64, i64* %2
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i64 %3, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8 0, i8* %4
%12 = getelementptr inbounds i8, i8* %4, i64 1
store i8 1, i8* %12
%13 = getelementptr inbounds i8, i8* %4, i64 2
store i8 2, i8* %13
%14 = getelementptr inbounds i8, i8* %4, i64 3
store i8 3, i8* %14
%15 = getelementptr inbounds i8, i8* %4, i64 4
store i8 4, i8* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%17 = getelementptr inbounds i8, i8* %4, i64 2
%18 = load i8, i8* %12
%19 = sext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %4, i64 3
%22 = load i8, i8* %17
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %4, i64 4
%26 = load i8, i8* %21
%27 = sext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i8, i8* %25
%30 = sext i8 %29 to i32
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %30)
ret void
}