#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 mode_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *aml_fio_file_to_char_stream(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mkstemp(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int umask(int);
int /*<<< orphan*/ unlink(char *);
FILE *aml_fio_strip_comments(FILE *f) {
  char *charStream = aml_fio_file_to_char_stream(f);
  if (!charStream)
    return NULL;
  fclose(f);
  char *tempFN = (char *)malloc(12 * sizeof(char));
  sprintf(tempFN, "temp.XXXXXX");
  mode_t oldMode = umask(077);
  f = fdopen(mkstemp(tempFN), "w");
  (void)umask(oldMode);
  fwrite(charStream, 1, strlen(charStream), f);
  fclose(f);
  f = fopen(tempFN, "r");
  unlink(tempFN);
  free(charStream);
  free(tempFN);
  return f;
}


x86 assembly (clang, -O0):
<aml_fio_strip_comments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <aml_fio_file_to_char_stream@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <aml_fio_strip_comments+0x31>
movq   $0x0,-0x8(%rbp)
jmp    12ad <aml_fio_strip_comments+0xed>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0xc,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xded(%rip),%rsi
call   10d0 <sprintf@plt>
mov    $0x3f,%edi
call   1080 <umask@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <mkstemp@plt>
mov    %eax,%edi
lea    0xdd5(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <umask@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aml_fio_strip_comments>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <aml_fio_file_to_char_stream@plt>
test   %rax,%rax
je     1273 <aml_fio_strip_comments+0xc3>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0xc,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
movabs $0x5858582e706d6574,%rax
58 58 58
mov    %rax,(%rbx)
movl   $0x585858,0x8(%rbx)
mov    $0x3f,%edi
call   1080 <umask@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   10a0 <mkstemp@plt>
lea    0xdfc(%rip),%rsi
mov    %eax,%edi
call   10b0 <fdopen@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1080 <umask@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   10d0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xdc3(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
jmp    1275 <aml_fio_strip_comments+0xc5>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"temp.XXXXXX\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
define i32* @aml_fio_strip_comments(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i8* @aml_fio_file_to_char_stream(i32* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32* null, i32** %2
br label %41
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
%15 = call i64 @malloc(i32 12)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @umask(i32 63)
store i32 %19, i32* %6
%20 = load i8*, i8** %5
%21 = call i32 @mkstemp(i8* %20)
%22 = call i32* @fdopen(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %3
%23 = load i32, i32* %6
%24 = call i32 @umask(i32 %23)
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = load i32*, i32** %3
%29 = call i32 @fwrite(i8* %25, i32 1, i32 %27, i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %5
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %3
%34 = load i8*, i8** %5
%35 = call i32 @unlink(i8* %34)
%36 = load i8*, i8** %4
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %5
%39 = call i32 @free(i8* %38)
%40 = load i32*, i32** %3
store i32* %40, i32** %2
br label %41
41: ; preds = %12, %11
%42 = load i32*, i32** %2
ret i32* %42
}

LLVM IR (-O2):
@.str = [12 x i8] c"temp.XXXXXX\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
define noalias i32* @aml_fio_strip_comments(i32* %0) {
%2 = tail call i8* @aml_fio_file_to_char_stream(i32* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i32 @fclose(i32* %0)
%6 = tail call i64 @malloc(i32 12)
%7 = inttoptr i64 %6 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %7, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 12, i1 false)
%8 = tail call i32 @umask(i32 63)
%9 = tail call i32 @mkstemp(i8* %7)
%10 = tail call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @umask(i32 %8)
%12 = tail call i32 @strlen(i8* %2)
%13 = tail call i32 @fwrite(i8* %2, i32 1, i32 %12, i32* %10)
%14 = tail call i32 @fclose(i32* %10)
%15 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @unlink(i8* %7)
%17 = tail call i32 @free(i8* %2)
%18 = tail call i32 @free(i8* %7)
br label %19
19: ; preds = %1, %4
%20 = phi i32* [ %15, %4 ], [ null, %1 ]
ret i32* %20
}