#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 */
struct aiocb {
  int aio_offset;
};

/* Variables and functions */
scalar_t__ EINPROGRESS;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ aio_error(struct aiocb *);
int /*<<< orphan*/ aio_read(struct aiocb *);
int aio_return(struct aiocb *);
int /*<<< orphan*/ aio_suspend(struct aiocb **, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ aio_write(struct aiocb *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct aiocb *, int /*<<< orphan*/, int);
int open(char *, int, int);
int /*<<< orphan*/ populate_aiocb(struct aiocb *, int, int /*<<< orphan*/, int,
                                  char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main() {
  struct aiocb a_write, a_read;
  struct aiocb *cblist[3];
  int err_r, err_w;
  int read_n = 0;
  int fd;
  char read_buf[100];
  char write_buf[100];
  fd = open("Temp.txt", O_CREAT | O_RDWR, 0644);
  memset(&a_write, 0, sizeof(struct aiocb));
  memset(&a_read, 0, sizeof(struct aiocb));
  populate_aiocb(&a_read, fd, 0, 100 - 1, read_buf);
  populate_aiocb(&a_write, fd, 0, 100 - 1, write_buf);
  printf("\n Enter Data for writing into the file\n");
  while (1) {
    scanf("%100s", write_buf);
    if (strcmp(write_buf, "EOF") == 0)
      break;
    aio_write(&a_write);
    if (err_r = aio_error(&a_write) == EINPROGRESS) {
      cblist[0] = &a_write;
      aio_suspend(cblist, 1, NULL);
    }
    a_write.aio_offset += aio_return(&a_write);
  }
  lseek(fd, 0, SEEK_SET);
  printf("\n Data in Temp.txt file\n");
  while (1) {
    aio_read(&a_read);
    if (err_r = aio_error(&a_read) == EINPROGRESS) {
      cblist[0] = &a_read;
      aio_suspend(cblist, 1, NULL);
    }
    read_n = aio_return(&a_read);
    printf("\n %s ", read_buf);
    if (read_n != 100 - 1)
      break;
    else {
      a_read.aio_offset += read_n;
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
or     (%rax),%esi
lea    0xdfe(%rip),%rdi
mov    $0x1a4,%edx
call   10f0 <open@plt>
mov    %eax,-0x40(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x40(%rbp),%esi
lea    -0xb0(%rbp),%r8
lea    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    $0x63,%ecx
call   1080 <populate_aiocb@plt>
mov    -0x40(%rbp),%esi
lea    -0x120(%rbp),%r8
lea    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    $0x63,%ecx
call   1080 <populate_aiocb@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdb2(%rip),%rdi
call   10e0 <scanf@plt>
lea    -0x120(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a6 <main+0xd6>
jmp    130b <main+0x13b>
lea    -0x8(%rbp),%rdi
call   1030 <aio_write@plt>
lea    -0x8(%rbp),%rdi
call   10b0 <aio_error@plt>
mov    0x2d19(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x34(%rbp)
test   $0x1,%al
jne    12dd <main+0x10d>
jmp    12f7 <main+0x127>
lea    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <aio_suspend@plt>
lea    -0x8(%rbp),%rdi
call   10c0 <aio_return@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1271 <main+0xa1>
mov    -0x40(%rbp),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <aio_read@plt>
lea    -0x10(%rbp),%rdi
call   10b0 <aio_error@plt>
mov    0x2c93(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x34(%rbp)
test   $0x1,%al
jne    1363 <main+0x193>
jmp    137d <main+0x1ad>
lea    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <aio_suspend@plt>
lea    -0x10(%rbp),%rdi
call   10c0 <aio_return@plt>
mov    %eax,-0x3c(%rbp)
lea    -0xb0(%rbp),%rsi
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x63,-0x3c(%rbp)
je     13ad <main+0x1dd>
jmp    13bb <main+0x1eb>
mov    -0x3c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    132c <main+0x15c>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e00(%rip),%rax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdf6(%rip),%rdi
mov    $0x1a4,%edx
call   1100 <open@plt>
mov    %eax,%ebp
lea    0x18(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0xb0(%rsp),%r8
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    $0x63,%ecx
call   1090 <populate_aiocb@plt>
lea    0x40(%rsp),%r14
mov    %r13,%rdi
mov    %ebp,0xc(%rsp)
mov    %ebp,%esi
xor    %edx,%edx
mov    $0x63,%ecx
mov    %r14,%r8
call   1090 <populate_aiocb@plt>
lea    0xd9e(%rip),%rdi
call   1030 <puts@plt>
lea    0xd82(%rip),%rdi
mov    %r14,%rsi
call   10f0 <scanf@plt>
lea    0xd79(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1314 <main+0x134>
mov    0x2d2e(%rip),%r15
lea    0xd58(%rip),%r12
lea    0x40(%rsp),%rbp
lea    0xd52(%rip),%r14
jmp    12e7 <main+0x107>
nop
mov    %r13,%rdi
call   10d0 <aio_return@plt>
add    %eax,0x18(%rsp)
mov    %r12,%rdi
mov    %rbp,%rsi
call   10f0 <scanf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1314 <main+0x134>
mov    %r13,%rdi
call   1040 <aio_write@plt>
mov    %r13,%rdi
call   10c0 <aio_error@plt>
cmp    (%r15),%rax
jne    12c0 <main+0xe0>
mov    %r13,0x20(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   10e0 <aio_suspend@plt>
jmp    12c0 <main+0xe0>
mov    0x2cad(%rip),%rax
mov    (%rax),%edx
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0xd11(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c9d(%rip),%r13
lea    0x20(%rsp),%r14
lea    0xccc(%rip),%r15
lea    0xb0(%rsp),%r12
nop
mov    %rbx,%rdi
call   10b0 <aio_read@plt>
mov    %rbx,%rdi
call   10c0 <aio_error@plt>
cmp    0x0(%r13),%rax
jne    137a <main+0x19a>
mov    %rbx,0x20(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   10e0 <aio_suspend@plt>
mov    %rbx,%rdi
call   10d0 <aio_return@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x63,%ebp
jne    139d <main+0x1bd>
addl   $0x63,0x10(%rsp)
jmp    1350 <main+0x170>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.aiocb = type { i32 }
@.str = [9 x i8] c"Temp.txt\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [40 x i8] c"\0A Enter Data for writing into the file\0A\00"
@.str.2 = [6 x i8] c"%100s\00"
@.str.3 = [4 x i8] c"EOF\00"
@EINPROGRESS = global i64 0
@SEEK_SET = global i32 0
@.str.4 = [25 x i8] c"\0A Data in Temp.txt file\0A\00"
@.str.5 = [6 x i8] c"\0A %s \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.aiocb
%3 = alloca %struct.aiocb
%4 = alloca [3 x %struct.aiocb*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i8]
%10 = alloca [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %7
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDWR
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i32 420)
store i32 %14, i32* %8
%15 = call i32 @memset(%struct.aiocb* %2, i32 0, i32 4)
%16 = call i32 @memset(%struct.aiocb* %3, i32 0, i32 4)
%17 = load i32, i32* %8
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%19 = call i32 @populate_aiocb(%struct.aiocb* %3, i32 %17, i32 0, i32 99, i8* %18)
%20 = load i32, i32* %8
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%22 = call i32 @populate_aiocb(%struct.aiocb* %2, i32 %20, i32 0, i32 99, i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %0, %41
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%26 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %46
31: ; preds = %24
%32 = call i32 @aio_write(%struct.aiocb* %2)
%33 = call i64 @aio_error(%struct.aiocb* %2)
%34 = load i64, i64* @EINPROGRESS
%35 = icmp eq i64 %33, %34
%36 = zext i1 %35 to i32
store i32 %36, i32* %5
br i1 %35, label %37, label %41
37: ; preds = %31
%38 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
store %struct.aiocb* %2, %struct.aiocb** %38
%39 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
%40 = call i32 @aio_suspend(%struct.aiocb** %39, i32 1, i32* null)
br label %41
41: ; preds = %37, %31
%42 = call i32 @aio_return(%struct.aiocb* %2)
%43 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %2, i32 0, i32 0
%44 = load i32, i32* %43
%45 = add nsw i32 %44, %42
store i32 %45, i32* %43
br label %24
46: ; preds = %30
%47 = load i32, i32* %8
%48 = load i32, i32* @SEEK_SET
%49 = call i32 @lseek(i32 %47, i32 0, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %46, %73
%52 = call i32 @aio_read(%struct.aiocb* %3)
%53 = call i64 @aio_error(%struct.aiocb* %3)
%54 = load i64, i64* @EINPROGRESS
%55 = icmp eq i64 %53, %54
%56 = zext i1 %55 to i32
store i32 %56, i32* %5
br i1 %55, label %57, label %61
57: ; preds = %51
%58 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
store %struct.aiocb* %3, %struct.aiocb** %58
%59 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
%60 = call i32 @aio_suspend(%struct.aiocb** %59, i32 1, i32* null)
br label %61
61: ; preds = %57, %51
%62 = call i32 @aio_return(%struct.aiocb* %3)
store i32 %62, i32* %7
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %7
%66 = icmp ne i32 %65, 99
br i1 %66, label %67, label %68
67: ; preds = %61
br label %74
68: ; preds = %61
%69 = load i32, i32* %7
%70 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %3, i32 0, i32 0
%71 = load i32, i32* %70
%72 = add nsw i32 %71, %69
store i32 %72, i32* %70
br label %73
73: ; preds = %68
br label %51
74: ; preds = %67
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
%struct.aiocb = type { i32 }
@.str = [9 x i8] c"Temp.txt\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [6 x i8] c"%100s\00"
@.str.3 = [4 x i8] c"EOF\00"
@EINPROGRESS = global i64 0
@SEEK_SET = global i32 0
@.str.5 = [6 x i8] c"\0A %s \00"
@str = [39 x i8] c"\0A Enter Data for writing into the file\00"
@str.6 = [24 x i8] c"\0A Data in Temp.txt file\00"
define i32 @main() {
%1 = alloca %struct.aiocb
%2 = alloca %struct.aiocb
%3 = alloca [3 x %struct.aiocb*]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = bitcast %struct.aiocb* %1 to i8*
%7 = bitcast %struct.aiocb* %2 to i8*
%8 = bitcast [3 x %struct.aiocb*]* %3 to i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDWR
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i32 420)
%15 = call i32 @memset(%struct.aiocb* %1, i32 0, i32 4)
%16 = call i32 @memset(%struct.aiocb* %2, i32 0, i32 4)
%17 = call i32 @populate_aiocb(%struct.aiocb* %2, i32 %14, i32 0, i32 99, i8* %9)
%18 = call i32 @populate_aiocb(%struct.aiocb* %1, i32 %14, i32 0, i32 99, i8* %10)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%21 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %40, label %23
23: ; preds = %0
%24 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %3, i64 0, i64 0
%25 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 0
br label %26
26: ; preds = %23, %33
%27 = call i32 @aio_write(%struct.aiocb* %1)
%28 = call i64 @aio_error(%struct.aiocb* %1)
%29 = load i64, i64* @EINPROGRESS
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %26
store %struct.aiocb* %1, %struct.aiocb** %24
%32 = call i32 @aio_suspend(%struct.aiocb** %24, i32 1, i32* null)
br label %33
33: ; preds = %31, %26
%34 = call i32 @aio_return(%struct.aiocb* %1)
%35 = load i32, i32* %25
%36 = add nsw i32 %35, %34
store i32 %36, i32* %25
%37 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%38 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %26
40: ; preds = %33, %0
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @lseek(i32 %14, i32 0, i32 %41)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
%44 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %3, i64 0, i64 0
%45 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %2, i64 0, i32 0
br label %46
46: ; preds = %57, %40
%47 = call i32 @aio_read(%struct.aiocb* %2)
%48 = call i64 @aio_error(%struct.aiocb* %2)
%49 = load i64, i64* @EINPROGRESS
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %46
store %struct.aiocb* %2, %struct.aiocb** %44
%52 = call i32 @aio_suspend(%struct.aiocb** %44, i32 1, i32* null)
br label %53
53: ; preds = %51, %46
%54 = call i32 @aio_return(%struct.aiocb* %2)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%56 = icmp eq i32 %54, 99
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32, i32* %45
%59 = add nsw i32 %58, 99
store i32 %59, i32* %45
br label %46
60: ; preds = %53
%61 = call i32 @close(i32 %14)
ret i32 0
}