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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
void copy_pre_processor_directives_from_dut(const char *filename) {
  char buf[1024];
  FILE *f = fopen(filename, "r");
  if (NULL == f) {
    fprintf(stderr, "ERROR: Unable to open '%s'\n", filename);
    return;
  }
  while (fgets(buf, sizeof(buf), f)) {
    if ('#' != buf[0]) {
      continue;
    }
    printf("%s", buf);
  }
  fclose(f);
  puts("#include <stdarg.h>");
  puts("");
}


x86 assembly (clang, -O0):
<copy_pre_processor_directives_from_dut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x418(%rbp)
xor    %eax,%eax
cmp    -0x418(%rbp),%rax
jne    11b3 <copy_pre_processor_directives_from_dut+0x53>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe59(%rip),%rsi
call   1070 <fprintf@plt>
jmp    122f <copy_pre_processor_directives_from_dut+0xcf>
jmp    11b8 <copy_pre_processor_directives_from_dut+0x58>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     120b <copy_pre_processor_directives_from_dut+0xab>
movsbl -0x410(%rbp),%ecx
mov    $0x23,%eax
cmp    %ecx,%eax
je     11f3 <copy_pre_processor_directives_from_dut+0x93>
jmp    11b8 <copy_pre_processor_directives_from_dut+0x58>
lea    -0x410(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
jmp    11b8 <copy_pre_processor_directives_from_dut+0x58>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_pre_processor_directives_from_dut>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1213 <copy_pre_processor_directives_from_dut+0xa3>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e8 <copy_pre_processor_directives_from_dut+0x78>
lea    0xe6b(%rip),%r14
mov    %rsp,%r15
jmp    11d5 <copy_pre_processor_directives_from_dut+0x65>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e8 <copy_pre_processor_directives_from_dut+0x78>
cmpb   $0x23,(%rsp)
jne    11c0 <copy_pre_processor_directives_from_dut+0x50>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
jmp    11c0 <copy_pre_processor_directives_from_dut+0x50>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    %r14,%rdx
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"ERROR: Unable to open '%s'\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c"#include <stdarg.h>\00"
@.str.4 = [1 x i8] zeroinitializer
define void @copy_pre_processor_directives_from_dut(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %33
13: ; preds = %1
br label %14
14: ; preds = %25, %24, %13
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 35, %22
br i1 %23, label %24, label %25
24: ; preds = %19
br label %14
25: ; preds = %19
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %14
28: ; preds = %14
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
%31 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %28, %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"ERROR: Unable to open '%s'\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c"#include <stdarg.h>\00"
define void @copy_pre_processor_directives_from_dut(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
12: ; preds = %6, %17
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 35
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %17
17: ; preds = %15, %12
%18 = call i64 @fgets(i8* %3, i32 1024, i32* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %17, %6
%21 = call i32 @fclose(i32* %4)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @putchar(i32 10)
br label %24
24: ; preds = %20, %9
ret void
}