#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__ retval;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int file_length(char *);
int /*<<< orphan*/ print_test_name(char *, char const *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
char *strerror(int);
int system(char *);
void stdio_test(const char *filetype) {
  static char buffer[256];
  int file_size, retval;
  print_test_name("stdio_test", filetype);
  snprintf(buffer, sizeof(buffer), "./stdout_test %s > stdio.%s", filetype,
           filetype);
  if ((retval = system(buffer))) {
    retval = (((retval)&0xff) == 0) ? (((retval)&0xff00) >> 8) : 1;
    printf("%s : %s", buffer, (strerror(retval)));
    exit(1);
  };
  snprintf(buffer, sizeof(buffer), "stdio.%s", filetype);
  if ((file_size = file_length(buffer)) < 12345) {
    printf("\n    Error : test file '%s' too small (%d).\n\n", buffer,
           file_size);
    exit(1);
  };
  snprintf(buffer, sizeof(buffer), "./stdin_test %s < stdio.%s", filetype,
           filetype);
  if ((retval = system(buffer))) {
    retval = (((retval)&0xff) == 0) ? (((retval)&0xff00) >> 8) : 1;
    printf("%s : %s", buffer, (strerror(retval)));
    exit(1);
  };
  snprintf(buffer, sizeof(buffer), "rm stdio.%s", filetype);
  if ((retval = system(buffer))) {
    retval = (((retval)&0xff) == 0) ? (((retval)&0xff00) >> 8) : 1;
    printf("%s : %s", buffer, (strerror(retval)));
    exit(1);
  };
  puts("ok");
  return;
}


x86 assembly (clang, -O0):
<stdio_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1070 <print_test_name@plt>
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2ec5(%rip),%rdi
mov    $0x100,%esi
lea    0xe54(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    0x2eab(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     1237 <stdio_test+0xb7>
mov    -0x10(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    11fa <stdio_test+0x7a>
mov    -0x10(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
jmp    1207 <stdio_test+0x87>
mov    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1207 <stdio_test+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
lea    0xe08(%rip),%rdi
lea    0x2e4a(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rcx
lea    0x2e2e(%rip),%rdi
mov    $0x100,%esi
lea    0xe21(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    0x2e14(%rip),%rdi
call   1080 <file_length@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x3039,%eax
jge    1291 <stdio_test+0x111>
mov    -0xc(%rbp),%edx
lea    0xdb6(%rip),%rdi
lea    0x2df0(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2dd0(%rip),%rdi
mov    $0x100,%esi
lea    0xdb1(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    0x2db6(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     132c <stdio_test+0x1ac>
mov    -0x10(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    12ef <stdio_test+0x16f>
mov    -0x10(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
jmp    12fc <stdio_test+0x17c>
mov    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12fc <stdio_test+0x17c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
lea    0xd13(%rip),%rdi
lea    0x2d55(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rcx
lea    0x2d39(%rip),%rdi
mov    $0x100,%esi
lea    0xd35(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    0x2d1f(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     13c3 <stdio_test+0x243>
mov    -0x10(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
jne    1386 <stdio_test+0x206>
mov    -0x10(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    1393 <stdio_test+0x213>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1393 <stdio_test+0x213>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
lea    0xc7c(%rip),%rdi
lea    0x2cbe(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xcba(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdio_test>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
call   1070 <print_test_name@plt>
lea    0x2ed3(%rip),%r14
lea    0xe67(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
test   %eax,%eax
jne    126a <stdio_test+0xea>
lea    0x2ea0(%rip),%r14
lea    0xe98(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1080 <file_length@plt>
cmp    $0x3038,%eax
jle    129e <stdio_test+0x11e>
lea    0x2e6d(%rip),%r14
lea    0xe53(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
test   %eax,%eax
jne    126a <stdio_test+0xea>
lea    0x2e3e(%rip),%r14
lea    0xe3f(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
test   %eax,%eax
jne    126a <stdio_test+0xea>
lea    0xe26(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>
test   %al,%al
movzbl %ah,%edi
mov    $0x1,%eax
cmovne %eax,%edi
call   10a0 <strerror@plt>
lea    0xda4(%rip),%rdi
lea    0x2de6(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd8a(%rip),%rdi
lea    0x2dc4(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdio_test.buffer = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"stdio_test\00"
@.str.1 = [28 x i8] c"./stdout_test %s > stdio.%s\00"
@.str.2 = [8 x i8] c"%s : %s\00"
@.str.3 = [9 x i8] c"stdio.%s\00"
@.str.4 = [46 x i8] c"\0A Error : test file '%s' too small (%d).\0A\0A\00"
@.str.5 = [27 x i8] c"./stdin_test %s < stdio.%s\00"
@.str.6 = [12 x i8] c"rm stdio.%s\00"
@.str.7 = [3 x i8] c"ok\00"
define void @stdio_test(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @print_test_name(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %8)
%10 = call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
store i32 %10, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %1
%13 = load i32, i32* %4
%14 = and i32 %13, 255
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %4
%18 = and i32 %17, 65280
%19 = ashr i32 %18, 8
br label %21
20: ; preds = %12
br label %21
21: ; preds = %20, %16
%22 = phi i32 [ %19, %16 ], [ 1, %20 ]
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %1
%28 = load i8*, i8** %2
%29 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = call i32 @file_length(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
store i32 %30, i32* %3
%31 = icmp slt i32 %30, 12345
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* %3
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i8*, i8** %2
%38 = load i8*, i8** %2
%39 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* %38)
%40 = call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
store i32 %40, i32* %4
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %36
%43 = load i32, i32* %4
%44 = and i32 %43, 255
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* %4
%48 = and i32 %47, 65280
%49 = ashr i32 %48, 8
br label %51
50: ; preds = %42
br label %51
51: ; preds = %50, %46
%52 = phi i32 [ %49, %46 ], [ 1, %50 ]
store i32 %52, i32* %4
%53 = load i32, i32* %4
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %36
%58 = load i8*, i8** %2
%59 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %58)
%60 = call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
store i32 %60, i32* %4
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %77
62: ; preds = %57
%63 = load i32, i32* %4
%64 = and i32 %63, 255
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i32, i32* %4
%68 = and i32 %67, 65280
%69 = ashr i32 %68, 8
br label %71
70: ; preds = %62
br label %71
71: ; preds = %70, %66
%72 = phi i32 [ %69, %66 ], [ 1, %70 ]
store i32 %72, i32* %4
%73 = load i32, i32* %4
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %57
%78 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdio_test.buffer = internal global [256 x i8] zeroinitializer
@.str = [11 x i8] c"stdio_test\00"
@.str.1 = [28 x i8] c"./stdout_test %s > stdio.%s\00"
@.str.2 = [8 x i8] c"%s : %s\00"
@.str.3 = [9 x i8] c"stdio.%s\00"
@.str.4 = [46 x i8] c"\0A Error : test file '%s' too small (%d).\0A\0A\00"
@.str.5 = [27 x i8] c"./stdin_test %s < stdio.%s\00"
@.str.6 = [12 x i8] c"rm stdio.%s\00"
@.str.7 = [3 x i8] c"ok\00"
define void @stdio_test(i8* %0) {
%2 = tail call i32 @print_test_name(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %0)
%4 = tail call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = and i32 %4, 255
%8 = icmp eq i32 %7, 0
%9 = lshr i32 %4, 8
%10 = and i32 %9, 255
%11 = select i1 %8, i32 %10, i32 1
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%17 = tail call i32 @file_length(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
%18 = icmp slt i32 %17, 12345
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 %17)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %0)
%24 = tail call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %22
%27 = and i32 %24, 255
%28 = icmp eq i32 %27, 0
%29 = lshr i32 %24, 8
%30 = and i32 %29, 255
%31 = select i1 %28, i32 %30, i32 1
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %32)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %22
%36 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%37 = tail call i32 @system(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %48, label %39
39: ; preds = %35
%40 = and i32 %37, 255
%41 = icmp eq i32 %40, 0
%42 = lshr i32 %37, 8
%43 = and i32 %42, 255
%44 = select i1 %41, i32 %43, i32 1
%45 = tail call i8* @strerror(i32 %44)
%46 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stdio_test.buffer, i64 0, i64 0), i8* %45)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %35
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret void
}