#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*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ asprintf(char **, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ *tmpfile();
int main(int argc, char *argv[]) {
  FILE *f = tmpfile();
  char obuf[99999], ibuf[sizeof obuf];
  char *line;
  size_t linesz;
  if (!f) {
    perror("tmpfile");
    return 1;
  }
  if (fputs("line\n", f) == EOF) {
    perror("fputs");
    return 1;
  }
  memset(obuf, 'z', sizeof obuf);
  memset(ibuf, 'y', sizeof ibuf);
  if (fwrite(obuf, sizeof obuf, 1, f) != 1) {
    perror("fwrite");
    return 1;
  }
  rewind(f);
  line = NULL;
  linesz = 0;
  if (getline(&line, &linesz, f) != 5) {
    perror("getline");
    return 1;
  }
  if (strcmp(line, "line\n")) {
    puts("Lines differ.  Test FAILED!");
    return 1;
  }
  if (fread(ibuf, sizeof ibuf, 1, f) != 1) {
    perror("fread");
    return 1;
  }
  if (memcmp(ibuf, obuf, sizeof ibuf)) {
    puts("Buffers differ.  Test FAILED!");
    return 1;
  }
  asprintf(&line, "GDB is free software and you are welcome to distribute "
                  "copies of it\n under certain conditions; type \"show "
                  "copying\" to see the conditions.\nThere is absolutely no "
                  "warranty for GDB; type \"show warranty\" for details.\n");
  puts("Test succeeded.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1207 <main+0x47>
lea    0xe0a(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
mov    -0x18(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%rax
jne    123f <main+0x7f>
lea    0xde0(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
lea    -0x186c0(%rbp),%rdi
mov    $0x7a,%esi
mov    $0x1869f,%edx
call   1070 <memset@plt>
lea    -0x30d60(%rbp),%rdi
mov    $0x79,%esi
mov    $0x1869f,%edx
call   1070 <memset@plt>
lea    -0x186c0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1869f,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     12a6 <main+0xe6>
lea    0xd7f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
movq   $0x0,-0x30d68(%rbp)
movq   $0x0,-0x30d70(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x30d68(%rbp),%rdi
lea    -0x30d70(%rbp),%rsi
call   10d0 <getline@plt>
cmp    $0x5,%eax
je     12fd <main+0x13d>
lea    0xd2f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
mov    -0x30d68(%rbp),%rdi
lea    0xcfd(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1332 <main+0x172>
lea    0xd02(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
lea    -0x30d60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1869f,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     136d <main+0x1ad>
lea    0xce3(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
lea    -0x30d60(%rbp),%rdi
lea    -0x186c0(%rbp),%rsi
mov    $0x1869f,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     13a7 <main+0x1e7>
lea    0xcaf(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cd <main+0x20d>
lea    -0x30d68(%rbp),%rdi
lea    0xcae(%rip),%rsi
call   10b0 <asprintf@plt>
lea    0xd78(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30d50,%rsp
xor    %eax,%eax
call   1090 <tmpfile@plt>
test   %rax,%rax
je     1313 <main+0x153>
mov    %rax,%rbx
lea    0xe23(%rip),%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
je     131c <main+0x15c>
lea    0x186b0(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x7a,%esi
mov    $0x1869f,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x79,%esi
mov    $0x1869f,%edx
call   1070 <memset@plt>
mov    $0x1,%r14d
mov    %rbp,%rdi
mov    $0x1869f,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    1330 <main+0x170>
mov    %rbx,%rdi
call   1050 <rewind@plt>
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   10d0 <getline@plt>
cmp    $0x5,%eax
jne    1339 <main+0x179>
mov    (%rsp),%rdi
lea    0xd7c(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12a7 <main+0xe7>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
jmp    134e <main+0x18e>
lea    0x10(%rsp),%rdi
mov    $0x1,%r14d
mov    $0x1869f,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1342 <main+0x182>
lea    0x10(%rsp),%rdi
lea    0x186b0(%rsp),%rsi
mov    $0x1869f,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     12f3 <main+0x133>
lea    0xd59(%rip),%rdi
call   1030 <puts@plt>
jmp    134e <main+0x18e>
lea    0xd69(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <asprintf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
jmp    134e <main+0x18e>
lea    0xce6(%rip),%rdi
jmp    1323 <main+0x163>
lea    0xceb(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r14d
jmp    134e <main+0x18e>
lea    0xcdd(%rip),%rdi
jmp    1349 <main+0x189>
lea    0xcdb(%rip),%rdi
jmp    1349 <main+0x189>
lea    0xcf6(%rip),%rdi
call   10c0 <perror@plt>
mov    %r14d,%eax
add    $0x30d50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"tmpfile\00"
@.str.1 = [6 x i8] c"line\0A\00"
@EOF = global i64 0
@.str.2 = [6 x i8] c"fputs\00"
@.str.3 = [7 x i8] c"fwrite\00"
@.str.4 = [8 x i8] c"getline\00"
@.str.5 = [28 x i8] c"Lines differ. Test FAILED!\00"
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [30 x i8] c"Buffers differ. Test FAILED!\00"
@.str.8 = [214 x i8] c"GDB is free software and you are welcome to distribute copies of it\0A under certain conditions; type \22show copying\22 to see the conditions.\0AThere is absolutely no warranty for GDB; type \22show warranty\22 for details.\0A\00"
@.str.9 = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [99999 x i8]
%8 = alloca [99999 x i8]
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32* (...) @tmpfile()
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %65
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = load i64, i64* @EOF
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %65
23: ; preds = %16
%24 = getelementptr inbounds [99999 x i8], [99999 x i8]* %7, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i8 signext 122, i32 99999)
%26 = getelementptr inbounds [99999 x i8], [99999 x i8]* %8, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i8 signext 121, i32 99999)
%28 = getelementptr inbounds [99999 x i8], [99999 x i8]* %7, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i32 @fwrite(i8* %28, i32 99999, i32 1, i32* %29)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %65
34: ; preds = %23
%35 = load i32*, i32** %6
%36 = call i32 @rewind(i32* %35)
store i8* null, i8** %9
store i64 0, i64* %10
%37 = load i32*, i32** %6
%38 = call i32 @getline(i8** %9, i64* %10, i32* %37)
%39 = icmp ne i32 %38, 5
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %65
42: ; preds = %34
%43 = load i8*, i8** %9
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %65
48: ; preds = %42
%49 = getelementptr inbounds [99999 x i8], [99999 x i8]* %8, i64 0, i64 0
%50 = load i32*, i32** %6
%51 = call i32 @fread(i8* %49, i32 99999, i32 1, i32* %50)
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %65
55: ; preds = %48
%56 = getelementptr inbounds [99999 x i8], [99999 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [99999 x i8], [99999 x i8]* %7, i64 0, i64 0
%58 = call i64 @memcmp(i8* %56, i8* %57, i32 99999)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %65
62: ; preds = %55
%63 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([214 x i8], [214 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %65
65: ; preds = %62, %60, %53, %46, %40, %32, %21, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [8 x i8] c"tmpfile\00"
@.str.1 = [6 x i8] c"line\0A\00"
@EOF = global i64 0
@.str.2 = [6 x i8] c"fputs\00"
@.str.3 = [7 x i8] c"fwrite\00"
@.str.4 = [8 x i8] c"getline\00"
@.str.5 = [28 x i8] c"Lines differ. Test FAILED!\00"
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [30 x i8] c"Buffers differ. Test FAILED!\00"
@.str.8 = [214 x i8] c"GDB is free software and you are welcome to distribute copies of it\0A under certain conditions; type \22show copying\22 to see the conditions.\0AThere is absolutely no warranty for GDB; type \22show warranty\22 for details.\0A\00"
@.str.9 = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [99999 x i8]
%4 = alloca [99999 x i8]
%5 = alloca i8*
%6 = alloca i64
%7 = tail call i32* (...) @tmpfile()
%8 = getelementptr inbounds [99999 x i8], [99999 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 0
%10 = bitcast i8** %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = icmp eq i32* %7, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %53
15: ; preds = %2
%16 = tail call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %53
21: ; preds = %15
%22 = call i32 @memset(i8* %8, i8 signext 122, i32 99999)
%23 = call i32 @memset(i8* %9, i8 signext 121, i32 99999)
%24 = call i32 @fwrite(i8* %8, i32 99999, i32 1, i32* %7)
%25 = icmp eq i32 %24, 1
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %53
28: ; preds = %21
%29 = call i32 @rewind(i32* %7)
store i8* null, i8** %5
store i64 0, i64* %6
%30 = call i32 @getline(i8** %5, i64* %6, i32* %7)
%31 = icmp eq i32 %30, 5
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %53
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %53
40: ; preds = %34
%41 = call i32 @fread(i8* %9, i32 99999, i32 1, i32* %7)
%42 = icmp eq i32 %41, 1
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %53
45: ; preds = %40
%46 = call i64 @memcmp(i8* %9, i8* %8, i32 99999)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %53
50: ; preds = %45
%51 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([214 x i8], [214 x i8]* @.str.8, i64 0, i64 0))
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %53
53: ; preds = %50, %48, %43, %38, %32, %26, %19, %13
%54 = phi i32 [ 1, %19 ], [ 1, %26 ], [ 1, %32 ], [ 1, %38 ], [ 1, %43 ], [ 1, %48 ], [ 0, %50 ], [ 1, %13 ]
ret i32 %54
}