#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 int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
void check1(const char *d, const char *f, const char *in) {
  int fd, cc;
  char n[512], buf[21000];
  sprintf(n, "%s/%s", d, f);
  fd = open(n, 0);
  if (fd < 0) {
    fprintf(stderr, "test-lab-3-b: open(%s): %s\n", n, strerror(errno));
    exit(1);
  }
  errno = 0;
  cc = read(fd, buf, sizeof(buf) - 1);
  if (cc != strlen(in)) {
    fprintf(stderr, "test-lab-3-b: read(%s) returned too little %d%s%s\n", n,
            cc, errno ? ": " : "", errno ? strerror(errno) : "");
    exit(1);
  }
  close(fd);
  buf[cc] = '\0';
  if (strncmp(buf, in, strlen(n)) != 0) {
    fprintf(stderr, "test-lab-3-b: read(%s) got \"%s\", not \"%s\"\n", n, buf,
            in);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<check1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5480,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe43(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1231 <check1+0xa1>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x543c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x5438(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x543c(%rbp),%edi
mov    -0x5438(%rbp),%rdx
mov    %rax,%rcx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2da0(%rip),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%edi
lea    -0x5430(%rbp),%rsi
mov    $0x5207,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x5440(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5440(%rbp),%eax
cmp    %ecx,%eax
je     133d <check1+0x1ad>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x545c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x5458(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x544c(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%rdx
lea    0xdd3(%rip),%rax
lea    0xd9f(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x5448(%rbp)
mov    0x2d0c(%rip),%rax
cmpq   $0x0,(%rax)
je     12f1 <check1+0x161>
mov    0x2cfb(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,-0x5468(%rbp)
jmp    1304 <check1+0x174>
lea    0xd8a(%rip),%rax
mov    %rax,-0x5468(%rbp)
jmp    1304 <check1+0x174>
mov    -0x5448(%rbp),%r8
mov    -0x544c(%rbp),%ecx
mov    -0x5458(%rbp),%rdx
mov    -0x545c(%rbp),%edi
mov    -0x5468(%rbp),%r9
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x5430(%rbp,%rax,1)
lea    -0x5430(%rbp),%rax
mov    %rax,-0x5478(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x5470(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5478(%rbp),%rdi
mov    -0x5470(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13c8 <check1+0x238>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rdx
lea    -0x5430(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xca1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
add    $0x5480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x5408,%rsp
mov    %rdx,%r14
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe53(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <open@plt>
test   %eax,%eax
js     1237 <check1+0xa7>
mov    %eax,%ebx
mov    0x2e09(%rip),%r15
movq   $0x0,(%r15)
lea    0x200(%rsp),%rsi
mov    %eax,%edi
mov    $0x5207,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    126f <check1+0xdf>
mov    %ebx,%edi
call   1050 <close@plt>
movslq %ebp,%rax
movb   $0x0,0x200(%rsp,%rax,1)
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    0x200(%rsp),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    128c <check1+0xfc>
add    $0x5408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da2(%rip),%rax
mov    (%rax),%ebx
mov    0x2d91(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xdb0(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%rdi
test   %rdi,%rdi
jne    12bb <check1+0x12b>
lea    0xdfb(%rip),%r8
mov    %r8,%r9
jmp    12ca <check1+0x13a>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
mov    %rsp,%rdx
lea    0x200(%rsp),%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
call   10b0 <strerror@plt>
mov    %rax,%r9
lea    0xd8b(%rip),%r8
lea    0xd51(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"test-lab-3-b: open(%s): %s\0A\00"
@errno = global i64 0
@.str.2 = [51 x i8] c"test-lab-3-b: read(%s) returned too little %d%s%s\0A\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [43 x i8] c"test-lab-3-b: read(%s) got \22%s\22, not \22%s\22\0A\00"
define void @check1(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca [21000 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%16 = call i32 @open(i8* %15, i32 0)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %3
store i64 0, i64* @errno
%27 = load i32, i32* %7
%28 = getelementptr inbounds [21000 x i8], [21000 x i8]* %10, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 20999)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %52
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%37 = load i32, i32* %8
%38 = load i64, i64* @errno
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%42 = load i64, i64* @errno
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %34
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
br label %48
47: ; preds = %34
br label %48
48: ; preds = %47, %44
%49 = phi i8* [ %46, %44 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), %47 ]
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %36, i32 %37, i8* %41, i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %26
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [21000 x i8], [21000 x i8]* %10, i64 0, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds [21000 x i8], [21000 x i8]* %10, i64 0, i64 0
%59 = load i8*, i8** %6
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i64 @strncmp(i8* %58, i8* %59, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %52
%65 = load i32, i32* @stderr
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%67 = getelementptr inbounds [21000 x i8], [21000 x i8]* %10, i64 0, i64 0
%68 = load i8*, i8** %6
%69 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %66, i8* %67, i8* %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"test-lab-3-b: open(%s): %s\0A\00"
@errno = global i64 0
@.str.2 = [51 x i8] c"test-lab-3-b: read(%s) returned too little %d%s%s\0A\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [43 x i8] c"test-lab-3-b: read(%s) got \22%s\22, not \22%s\22\0A\00"
define void @check1(i8* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca [21000 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [21000 x i8], [21000 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = call i32 @open(i8* %6, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = load i64, i64* @errno
%14 = tail call i8* @strerror(i64 %13)
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
store i64 0, i64* @errno
%18 = call i32 @read(i32 %9, i8* %7, i32 20999)
%19 = tail call i32 @strlen(i8* %2)
%20 = icmp eq i32 %18, %19
br i1 %20, label %32, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i8* @strerror(i64 %23)
br label %27
27: ; preds = %21, %25
%28 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), %21 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %25 ]
%29 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), %21 ], [ %26, %25 ]
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %18, i8* %28, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = tail call i32 @close(i32 %9)
%34 = sext i32 %18 to i64
%35 = getelementptr inbounds [21000 x i8], [21000 x i8]* %5, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @strlen(i8* %6)
%37 = call i64 @strncmp(i8* %7, i8* %2, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %7, i8* %2)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %32
ret void
}