#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ posix_memalign(void **, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd;
  char *ptr;
  fd = open("/dev/Sample", O_RDWR);
  if (fd < 0) {
    perror("error");
  }
  posix_memalign((void **)&ptr, 4096, 4096);
  memcpy(ptr, "krishna", strlen("krishna"));
  write(fd, ptr, 4096);
  printf("data is %s\n", ptr);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11bd <main+0x3d>
lea    0xe54(%rip),%rdi
call   1090 <perror@plt>
lea    -0x10(%rbp),%rdi
mov    $0x1000,%edx
mov    %edx,%esi
call   10a0 <posix_memalign@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe36(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xe24(%rip),%rsi
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     120c <main+0x8c>
lea    0x8(%rsp),%rdi
mov    $0x1000,%esi
mov    $0x1000,%edx
call   10a0 <posix_memalign@plt>
mov    0x8(%rsp),%rbx
lea    0xe4f(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%rsi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1090 <perror@plt>
jmp    11a3 <main+0x23>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/Sample\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"krishna\00"
@.str.3 = [12 x i8] c"data is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @posix_memalign(i8** %3, i32 4096, i32 4096)
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @memcpy(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = call i32 @write(i32 %15, i8* %16, i32 4096)
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/Sample\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"krishna\00"
@.str.3 = [12 x i8] c"data is %s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @posix_memalign(i8** %1, i32 4096, i32 4096)
%10 = load i8*, i8** %1
%11 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %1
%14 = call i32 @write(i32 %4, i8* %13, i32 4096)
%15 = load i8*, i8** %1
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = call i32 @close(i32 %4)
ret i32 0
}