#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void printdata(char *filename) {
  printf("\n\n print %s \n\n", filename);
  char buff[1024];
  int c;
  FILE *f;
  f = fopen(filename, "r");
  if (f == NULL)
    return;
  while ((fgets(buff, 1024, f)) != NULL)
    printf("%s", buff);
  printf(" \n\n end print %s \n\n", filename);
  fclose(f);
  return;
}


x86 assembly (clang, -O0):
<printdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    1189 <printdata+0x49>
jmp    11e4 <printdata+0xa4>
jmp    118e <printdata+0x4e>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11c8 <printdata+0x88>
lea    -0x410(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
jmp    118e <printdata+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printdata>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
lea    0xea8(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xea8(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d7 <printdata+0x97>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <printdata+0x80>
lea    0xe7e(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <printdata+0x60>
lea    0xe4d(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\0A\0A print %s \0A\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c" \0A\0A end print %s \0A\0A\00"
define void @printdata(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
br label %27
13: ; preds = %1
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"\0A\0A print %s \0A\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c" \0A\0A end print %s \0A\0A\00"
define void @printdata(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7, %10
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %7
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%16 = call i32 @fclose(i32* %5)
br label %17
17: ; preds = %1, %14
ret void
}