#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*/ assert(int);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fmemopen(int /*<<< orphan*/ *, int, char *);
long ftell(int /*<<< orphan*/ *);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
void test_autoalloc() {
  char str[] = "A quick test";
  FILE *fp;
  long pos;
  size_t nofw, nofr, i;
  int rc;
  fp = fmemopen(NULL, 512, "w+");
  assert(fp != NULL);
  for (i = 0; i < 512; i++) {
    nofw = fwrite("a", 1, 1, fp);
    assert(nofw == 1);
  }
  pos = ftell(fp);
  assert(pos == 512);
  nofw = fwrite("a", 1, 1, fp);
  assert(nofw == 0);
  rc = fclose(fp);
  assert(rc == 0);
}


x86 assembly (clang, -O0):
<test_autoalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xea1(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe9f(%rip),%eax
mov    %eax,-0x5(%rbp)
mov    0xe9a(%rip),%al
mov    %al,-0x1(%rbp)
xor    %eax,%eax
mov    %eax,%edi
mov    $0x200,%esi
lea    0xe88(%rip),%rdx
call   1030 <fmemopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0x200,-0x38(%rbp)
jae    11f4 <test_autoalloc+0xa4>
mov    -0x18(%rbp),%rcx
lea    0xe4f(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a8 <test_autoalloc+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x200,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rcx
lea    0xdef(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_autoalloc>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdx
xor    %edi,%edi
mov    $0x200,%esi
call   1030 <fmemopen@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    $0x200,%ebx
lea    0xe7e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
xor    %edi,%edi
cmp    $0x1,%rax
sete   %dil
call   1050 <assert@plt>
add    $0xffffffffffffffff,%rbx
jne    1190 <test_autoalloc+0x40>
mov    %r15,%rdi
call   1060 <ftell@plt>
xor    %edi,%edi
cmp    $0x200,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe29(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <assert@plt>

LLVM IR (-O0):
@__const.test_autoalloc.str = [13 x i8] c"A quick test\00"
@.str = [3 x i8] c"w+\00"
@.str.1 = [2 x i8] c"a\00"
define void @test_autoalloc() {
%1 = alloca [13 x i8]
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = bitcast [13 x i8]* %1 to i8*
%9 = call i32* @fmemopen(i32* null, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
store i64 0, i64* %6
br label %14
14: ; preds = %24, %0
%15 = load i64, i64* %6
%16 = icmp ult i64 %15, 512
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32*, i32** %2
%19 = call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %18)
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = icmp eq i64 %20, 1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
br label %24
24: ; preds = %17
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %14
27: ; preds = %14
%28 = load i32*, i32** %2
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %3
%30 = load i64, i64* %3
%31 = icmp eq i64 %30, 512
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32*, i32** %2
%35 = call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %34)
store i64 %35, i64* %4
%36 = load i64, i64* %4
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [2 x i8] c"a\00"
define void @test_autoalloc() {
%1 = tail call i32* @fmemopen(i32* null, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = icmp ne i32* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %11, %5 ]
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %1)
%8 = icmp eq i64 %7, 1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 512
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call i64 @ftell(i32* %1)
%15 = icmp eq i64 %14, 512
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %1)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @fclose(i32* %1)
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
ret void
}