#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 */
int /*<<< orphan*/ _IOFBF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char const *const, int /*<<< orphan*/ *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ setvbuf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/, int);
scalar_t__ strcmp(char const *const, char *);
size_t strlen(char const *const);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char name[] = "/tmp/tst-mmap-setvbuf.XXXXXX";
  char buf[4096];
  const char *const test = "Let's see if mmap stdio works with setvbuf.\n";
  char temp[strlen(test) + 1];
  int fd = mkstemp(name);
  FILE *f;
  if (fd == -1) {
    printf("%u: cannot open temporary file: %m\n", 36);
    exit(1);
  }
  f = fdopen(fd, "w");
  if (f == NULL) {
    printf("%u: cannot fdopen temporary file: %m\n", 43);
    exit(1);
  }
  fputs(test, f);
  fclose(f);
  f = fopen(name, "rm");
  if (f == NULL) {
    printf("%u: cannot fopen temporary file: %m\n", 53);
    exit(1);
  }
  if (setvbuf(f, buf, _IOFBF, sizeof buf)) {
    printf("%u: setvbuf failed: %m\n", 59);
    exit(1);
  }
  if (fread(temp, 1, strlen(test), f) != strlen(test)) {
    printf("%u: couldn't read the file back: %m\n", 65);
    exit(1);
  }
  temp[strlen(test)] = '\0';
  if (strcmp(test, temp)) {
    printf("%u: read different string than was written:\n%s%s", 73, test, temp);
    exit(1);
  }
  fclose(f);
  unlink(name);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1080,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe37(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe34(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe31(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe2f(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe2a(%rip),%al
mov    %al,-0x14(%rbp)
lea    0xe21(%rip),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x30(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,-0x1074(%rbp)
cmpl   $0xffffffff,-0x1074(%rbp)
jne    123c <main+0x8c>
lea    0xe24(%rip),%rdi
mov    $0x24,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1074(%rbp),%edi
lea    0xe25(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x1080(%rbp)
cmpq   $0x0,-0x1080(%rbp)
jne    1280 <main+0xd0>
lea    0xe06(%rip),%rdi
mov    $0x2b,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1080(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x1080(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x30(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x1080(%rbp)
cmpq   $0x0,-0x1080(%rbp)
jne    12e1 <main+0x131>
lea    0xdce(%rip),%rdi
mov    $0x35,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1080(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%ecx
call   10b0 <setvbuf@plt>
cmp    $0x0,%rax
je     1329 <main+0x179>
lea    0xdab(%rip),%rdi
mov    $0x3b,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x1070(%rbp),%rdi
mov    -0x1080(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2c,%edx
call   1040 <fread@plt>
cmp    $0x2c,%rax
je     136d <main+0x1bd>
lea    0xd7f(%rip),%rdi
mov    $0x41,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movb   $0x0,-0x1044(%rbp)
lea    -0x1070(%rbp),%rsi
lea    0xc9b(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     13bc <main+0x20c>
lea    -0x1070(%rbp),%rcx
lea    0xd5c(%rip),%rdi
mov    $0x49,%esi
lea    0xc72(%rip),%rdx
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1080(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1050,%rsp
movups 0xe4e(%rip),%xmm0
movups %xmm0,0xd(%rsp)
movaps 0xe35(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1080 <mkstemp@plt>
cmp    $0xffffffff,%eax
jne    11ed <main+0x3d>
lea    0xe67(%rip),%rdi
mov    $0x24,%esi
jmp    12e6 <main+0x136>
lea    0xe7a(%rip),%rsi
mov    %eax,%edi
call   1090 <fdopen@plt>
test   %rax,%rax
jne    1211 <main+0x61>
lea    0xe69(%rip),%rdi
mov    $0x2b,%esi
jmp    12e6 <main+0x136>
mov    %rax,%rbx
lea    0xe02(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe5a(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    125a <main+0xaa>
lea    0xe49(%rip),%rdi
mov    $0x35,%esi
jmp    12e6 <main+0x136>
mov    %rax,%rbx
mov    0x2d7c(%rip),%rax
mov    (%rax),%edx
lea    0x50(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1000,%ecx
call   10a0 <setvbuf@plt>
test   %rax,%rax
jne    12cc <main+0x11c>
lea    0x20(%rsp),%rdi
mov    $0x2c,%edx
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x2c,%rax
jne    12da <main+0x12a>
movb   $0x0,0x4c(%rsp)
lea    0xd77(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12f7 <main+0x147>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rsp,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xdeb(%rip),%rdi
mov    $0x3b,%esi
jmp    12e6 <main+0x136>
lea    0xdf5(%rip),%rdi
mov    $0x41,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xdfd(%rip),%rdi
lea    0xd18(%rip),%rdx
lea    0x20(%rsp),%rcx
mov    $0x49,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.name = [29 x i8] c"/tmp/tst-mmap-setvbuf.XXXXXX\00"
@.str = [45 x i8] c"Let's see if mmap stdio works with setvbuf.\0A\00"
@.str.1 = [36 x i8] c"%u: cannot open temporary file: %m\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [38 x i8] c"%u: cannot fdopen temporary file: %m\0A\00"
@.str.4 = [3 x i8] c"rm\00"
@.str.5 = [37 x i8] c"%u: cannot fopen temporary file: %m\0A\00"
@_IOFBF = global i32 0
@.str.6 = [24 x i8] c"%u: setvbuf failed: %m\0A\00"
@.str.7 = [37 x i8] c"%u: couldn't read the file back: %m\0A\00"
@.str.8 = [49 x i8] c"%u: read different string than was written:\0A%s%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [29 x i8]
%3 = alloca [4096 x i8]
%4 = alloca i8*
%5 = alloca [45 x i8]
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
%8 = bitcast [29 x i8]* %2 to i8*
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%10 = call i32 @mkstemp(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 36)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32, i32* %6
%18 = call i32* @fdopen(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 43)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32*, i32** %7
%26 = call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i32 0, i32 0), i32* %25)
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
%29 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 53)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %24
%37 = load i32*, i32** %7
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%39 = load i32, i32* @_IOFBF
%40 = call i64 @setvbuf(i32* %37, i8* %38, i32 %39, i32 4096)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 59)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = getelementptr inbounds [45 x i8], [45 x i8]* %5, i64 0, i64 0
%47 = load i32*, i32** %7
%48 = call i64 @fread(i8* %46, i32 1, i64 44, i32* %47)
%49 = icmp ne i64 %48, 44
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 65)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %45
%54 = getelementptr inbounds [45 x i8], [45 x i8]* %5, i64 0, i64 44
store i8 0, i8* %54
%55 = getelementptr inbounds [45 x i8], [45 x i8]* %5, i64 0, i64 0
%56 = call i64 @strcmp(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i32 0, i32 0), i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = getelementptr inbounds [45 x i8], [45 x i8]* %5, i64 0, i64 0
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i32 0, i32 0), i8* %59)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%66 = call i32 @unlink(i8* %65)
%67 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.name = [29 x i8] c"/tmp/tst-mmap-setvbuf.XXXXXX\00"
@.str = [45 x i8] c"Let's see if mmap stdio works with setvbuf.\0A\00"
@.str.1 = [36 x i8] c"%u: cannot open temporary file: %m\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [38 x i8] c"%u: cannot fdopen temporary file: %m\0A\00"
@.str.4 = [3 x i8] c"rm\00"
@.str.5 = [37 x i8] c"%u: cannot fopen temporary file: %m\0A\00"
@_IOFBF = global i32 0
@.str.6 = [24 x i8] c"%u: setvbuf failed: %m\0A\00"
@.str.7 = [37 x i8] c"%u: couldn't read the file back: %m\0A\00"
@.str.8 = [49 x i8] c"%u: read different string than was written:\0A%s%s\00"
define i32 @main() {
%1 = alloca [29 x i8]
%2 = alloca [4096 x i8]
%3 = alloca [45 x i8]
%4 = getelementptr inbounds [29 x i8], [29 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 36)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32* @fdopen(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 43)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 44, i64 1, i32* %13)
%20 = call i32 @fclose(i32* %13)
%21 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 53)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = load i32, i32* @_IOFBF
%28 = call i64 @setvbuf(i32* %21, i8* %5, i32 %27, i32 4096)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 59)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = call i64 @fread(i8* %6, i32 1, i64 44, i32* %21)
%35 = icmp eq i64 %34, 44
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 65)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 44
store i8 0, i8* %40
%41 = call i64 @strcmp(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %6)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %6)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
%47 = call i32 @fclose(i32* %21)
%48 = call i32 @unlink(i8* %4)
%49 = call i32 @exit(i32 0)
unreachable
}