#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 O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, struct record *, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fdWrite, n;
  struct record {
    int id;
    char name[80];
  };
  struct record ashish[3] = {
      {12345, "ashish"}, {54321, "divya"}, {543210, "rudra"}};
  char buffer[3 * 84];
  memcpy(&buffer[0 * 84], &ashish[0], 84);
  memcpy(&buffer[1 * 84], &ashish[1], 84);
  memcpy(&buffer[2 * 84], &ashish[2], 84);
  if ((fdWrite = open("datafile", O_CREAT | O_WRONLY,
                      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) {
    printf("open error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  if ((n = write(fdWrite, buffer, 84 * 3)) == -1) {
    printf("write error with errno = %d\n", errno);
    perror("datafile");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0xfc,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
add    $0x54,%rdi
lea    -0x120(%rbp),%rsi
add    $0x54,%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
add    $0xa8,%rdi
lea    -0x120(%rbp),%rsi
add    $0xa8,%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
or     (%rax),%esi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    0x2dcf(%rip),%rax
or     (%rax),%edx
mov    0x2dae(%rip),%rax
or     (%rax),%edx
mov    0x2d9d(%rip),%rax
or     (%rax),%edx
lea    0xed0(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1268 <main+0x108>
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xfc,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12b3 <main+0x153>
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
lea    0xe91(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    $0xfc,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
lea    0x54(%rsp),%rdi
lea    0x154(%rsp),%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
lea    0xa8(%rsp),%rdi
lea    0x1a8(%rsp),%rsi
mov    $0x54,%edx
call   1050 <memcpy@plt>
mov    0x2e2c(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dda(%rip),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dd8(%rip),%rax
or     (%rax),%edx
mov    0x2dc7(%rip),%rax
or     (%rax),%edx
lea    0xefa(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     122b <main+0xcb>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xfc,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xdd>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
lea    0xeca(%rip),%rdi
jmp    124d <main+0xed>
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
lea    0xed4(%rip),%rdi
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.record = type { i32, [80 x i8] }
%struct.record.0 = type opaque
@__const.main.ashish = [3 x %struct.record] [%struct.record { i32 12345, [80 x i8] c"ashish\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }, %struct.record { i32 54321, [80 x i8] c"divya\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }, %struct.record { i32 543210, [80 x i8] c"rudra\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }]
@.str = [9 x i8] c"datafile\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [28 x i8] c"open error with errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"write error with errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x %struct.record]
%9 = alloca [252 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [3 x %struct.record]* %8 to i8*
%11 = getelementptr inbounds [252 x i8], [252 x i8]* %9, i64 0, i64 0
%12 = getelementptr inbounds [3 x %struct.record], [3 x %struct.record]* %8, i64 0, i64 0
%13 = bitcast %struct.record* %12 to %struct.record.0*
%14 = call i32 @memcpy(i8* %11, %struct.record.0* %13, i32 84)
%15 = getelementptr inbounds [252 x i8], [252 x i8]* %9, i64 0, i64 84
%16 = getelementptr inbounds [3 x %struct.record], [3 x %struct.record]* %8, i64 0, i64 1
%17 = bitcast %struct.record* %16 to %struct.record.0*
%18 = call i32 @memcpy(i8* %15, %struct.record.0* %17, i32 84)
%19 = getelementptr inbounds [252 x i8], [252 x i8]* %9, i64 0, i64 168
%20 = getelementptr inbounds [3 x %struct.record], [3 x %struct.record]* %8, i64 0, i64 2
%21 = bitcast %struct.record* %20 to %struct.record.0*
%22 = call i32 @memcpy(i8* %19, %struct.record.0* %21, i32 84)
%23 = load i32, i32* @O_CREAT
%24 = load i32, i32* @O_WRONLY
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IROTH
%32 = or i32 %30, %31
%33 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %32)
store i32 %33, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %2
%36 = load i32, i32* @errno
%37 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %2
%41 = load i32, i32* %6
%42 = getelementptr inbounds [252 x i8], [252 x i8]* %9, i64 0, i64 0
%43 = call i32 @write(i32 %41, i8* %42, i32 252)
store i32 %43, i32* %7
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* @errno
%47 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
%struct.record = type { i32, [80 x i8] }
%struct.record.0 = type opaque
@__const.main.ashish = [3 x %struct.record] [%struct.record { i32 12345, [80 x i8] c"ashish\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }, %struct.record { i32 54321, [80 x i8] c"divya\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }, %struct.record { i32 543210, [80 x i8] c"rudra\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" }]
@.str = [9 x i8] c"datafile\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [28 x i8] c"open error with errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"write error with errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x %struct.record]
%4 = alloca [252 x i8]
%5 = bitcast [3 x %struct.record]* %3 to i8*
%6 = getelementptr inbounds [252 x i8], [252 x i8]* %4, i64 0, i64 0
%7 = bitcast [3 x %struct.record]* %3 to %struct.record.0*
%8 = call i32 @memcpy(i8* %6, %struct.record.0* %7, i32 84)
%9 = getelementptr inbounds [252 x i8], [252 x i8]* %4, i64 0, i64 84
%10 = getelementptr inbounds [3 x %struct.record], [3 x %struct.record]* %3, i64 0, i64 1
%11 = bitcast %struct.record* %10 to %struct.record.0*
%12 = call i32 @memcpy(i8* %9, %struct.record.0* %11, i32 84)
%13 = getelementptr inbounds [252 x i8], [252 x i8]* %4, i64 0, i64 168
%14 = getelementptr inbounds [3 x %struct.record], [3 x %struct.record]* %3, i64 0, i64 2
%15 = bitcast %struct.record* %14 to %struct.record.0*
%16 = call i32 @memcpy(i8* %13, %struct.record.0* %15, i32 84)
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_WRONLY
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRUSR
%21 = load i32, i32* @S_IWUSR
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IRGRP
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %2
%30 = load i32, i32* @errno
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %2
%35 = call i32 @write(i32 %27, i8* %6, i32 252)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* @errno
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
ret i32 0
}