#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*/ close_the_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ print_warning(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strlen(char *);
int gen_datacalls(char *dirname) {
  FILE *fp;
  char *fn = "data_calls.inc";
  char fname[512];
  if (dirname == NULL)
    return (1);
  if (strlen(dirname) > 0) {
    sprintf(fname, "%s/%s", dirname, fn);
  } else {
    sprintf(fname, "%s", fn);
  }
  if ((fp = fopen(fname, "w")) == NULL)
    return (1);
  print_warning(fp, fname);
  close_the_file(fp);
  return (0);
}


x86 assembly (clang, -O0):
<gen_datacalls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1181 <gen_datacalls+0x31>
movl   $0x1,-0x4(%rbp)
jmp    121c <gen_datacalls+0xcc>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    11b6 <gen_datacalls+0x66>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    11cf <gen_datacalls+0x7f>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x220(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <gen_datacalls+0xac>
movl   $0x1,-0x4(%rbp)
jmp    121c <gen_datacalls+0xcc>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <print_warning@plt>
mov    -0x18(%rbp),%rdi
call   1050 <close_the_file@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_datacalls>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
mov    $0x1,%ebp
test   %rdi,%rdi
je     11d6 <gen_datacalls+0x86>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
jle    118d <gen_datacalls+0x3d>
lea    0xe98(%rip),%rsi
lea    0xe82(%rip),%rcx
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11aa <gen_datacalls+0x5a>
movabs $0x636e692e736c6c,%rax
mov    %rax,0x7(%rsp)
movabs $0x6c61635f61746164,%rax
63 61 6c
mov    %rax,(%rsp)
lea    0xe64(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d6 <gen_datacalls+0x86>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <print_warning@plt>
mov    %rbx,%rdi
call   1050 <close_the_file@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"data_calls.inc\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @gen_datacalls(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %34
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
br label %23
19: ; preds = %10
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %14
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %4
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 1, i32* %2
br label %34
28: ; preds = %23
%29 = load i32*, i32** %4
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%31 = call i32 @print_warning(i32* %29, i8* %30)
%32 = load i32*, i32** %4
%33 = call i32 @close_the_file(i32* %32)
store i32 0, i32* %2
br label %34
34: ; preds = %28, %27, %9
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [15 x i8] c"data_calls.inc\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @gen_datacalls(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = tail call i64 @strlen(i8* %0)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
10: ; preds = %5
br label %11
11: ; preds = %10, %8
%12 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @print_warning(i32* %12, i8* %3)
%16 = call i32 @close_the_file(i32* %12)
br label %17
17: ; preds = %11, %1, %14
%18 = phi i32 [ 0, %14 ], [ 1, %1 ], [ 1, %11 ]
ret i32 %18
}