#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, char, int);
int main() {
  char buffer[20], buffer1[20];
  int count = 0;
  int fd = open("a.txt", O_RDONLY);
  int fd1 = open("b.txt", O_RDONLY);
  ssize_t rrv, rrv1;
  int diff = 0;
  if ((fd < 0) || (fd1 < 0)) {
    perror("Open error: ");
    return 1;
  }
  do {
    rrv = read(fd, buffer[0], 1);
    rrv1 = read(fd, buffer1[0], 1);
    if (buffer[0] != buffer1[0]) {
      diff = 1;
    }
    count++;
  } while ((rrv != 0) && (rrv1 != 0) || (diff = 1));
  if ((rrv < 0) || (rrv1 < 0)) {
    perror("read");
    return 2;
  }
  int crv = close(fd);
  int crv1 = close(fd1);
  if ((crv < 0) || (crv1 < 0)) {
    perror("close");
    return 3;
  }
  printf("%d\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x48(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     11b1 <main+0x61>
cmpl   $0x0,-0x4c(%rbp)
jge    11c9 <main+0x79>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x180>
jmp    11ce <main+0x7e>
mov    -0x48(%rbp),%edi
mov    $0x1,%edx
movsbl -0x20(%rbp),%esi
call   1050 <read@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%edi
mov    $0x1,%edx
movsbl -0x40(%rbp),%esi
call   1050 <read@plt>
mov    %rax,-0x60(%rbp)
movsbl -0x20(%rbp),%eax
movsbl -0x40(%rbp),%ecx
cmp    %ecx,%eax
je     120f <main+0xbf>
movl   $0x1,-0x64(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1233 <main+0xe3>
mov    $0x1,%al
cmpq   $0x0,-0x60(%rbp)
mov    %al,-0x6d(%rbp)
jne    123f <main+0xef>
movl   $0x1,-0x64(%rbp)
mov    $0x1,%al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    11ce <main+0x7e>
cmpq   $0x0,-0x58(%rbp)
jl     1260 <main+0x110>
cmpq   $0x0,-0x60(%rbp)
jge    1278 <main+0x128>
lea    0xdb2(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12d0 <main+0x180>
mov    -0x48(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x68(%rbp)
mov    -0x4c(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     12a2 <main+0x152>
cmpl   $0x0,-0x6c(%rbp)
jge    12ba <main+0x16a>
lea    0xd75(%rip),%rdi
call   1070 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    12d0 <main+0x180>
mov    -0x44(%rbp),%esi
lea    0xd60(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%r14
mov    (%r14),%esi
lea    0xebb(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
mov    (%r14),%esi
lea    0xeb0(%rip),%rdi
call   1040 <open@plt>
or     %ebx,%eax
js     117e <main+0x4e>
nop
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <read@plt>
jmp    1160 <main+0x30>
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"a.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"b.txt\00"
@.str.2 = [13 x i8] c"Open error: \00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
store i32 0, i32* %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %0
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18, %0
%22 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %76
23: ; preds = %18
br label %24
24: ; preds = %51, %23
%25 = load i32, i32* %5
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%27 = load i8, i8* %26
%28 = call i64 @read(i32 %25, i8 signext %27, i32 1)
store i64 %28, i64* %7
%29 = load i32, i32* %5
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%31 = load i8, i8* %30
%32 = call i64 @read(i32 %29, i8 signext %31, i32 1)
store i64 %32, i64* %8
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %35, %38
br i1 %39, label %40, label %41
40: ; preds = %24
store i32 1, i32* %9
br label %41
41: ; preds = %40, %24
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %44
44: ; preds = %41
%45 = load i64, i64* %7
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i64, i64* %8
%49 = icmp ne i64 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %47, %44
store i32 1, i32* %9
br label %51
51: ; preds = %50, %47
%52 = phi i1 [ true, %47 ], [ true, %50 ]
br i1 %52, label %24, label %53
53: ; preds = %51
%54 = load i64, i64* %7
%55 = icmp slt i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i64, i64* %8
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56, %53
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %76
61: ; preds = %56
%62 = load i32, i32* %5
%63 = call i32 @close(i32 %62)
store i32 %63, i32* %10
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
store i32 %65, i32* %11
%66 = load i32, i32* %10
%67 = icmp slt i32 %66, 0
br i1 %67, label %71, label %68
68: ; preds = %61
%69 = load i32, i32* %11
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68, %61
%72 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %1
br label %76
73: ; preds = %68
%74 = load i32, i32* %4
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %74)
store i32 0, i32* %1
br label %76
76: ; preds = %73, %71, %59, %21
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
@.str = [6 x i8] c"a.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"b.txt\00"
@.str.2 = [13 x i8] c"Open error: \00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = or i32 %4, %2
%6 = icmp sgt i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
9: ; preds = %0, %9
%10 = tail call i64 @read(i32 %2, i8 signext undef, i32 1)
%11 = tail call i64 @read(i32 %2, i8 signext undef, i32 1)
br label %9
}