#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(scalar_t__);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int open_files(char scrdsk[]) {
  char *outfile;
  FILE *fd;
  char dir1[132];
  strcpy(dir1, scrdsk);
  strcat(dir1, "/best_tmp");
  outfile = (char *)malloc(200);
  sprintf(outfile, dir1);
  if ((fd = fopen(outfile, "w")) == NULL) {
    if (fprintf(stderr, "File open failed in write_pulses for\n") == EOF)
      exit(EOF);
    if (fprintf(stderr, "%s\n", outfile) == EOF)
      exit(EOF);
    return (EOF);
  }
  fclose(fd);
  if ((fd = fopen(outfile, "w")) == NULL) {
    if (fprintf(stderr, "File open failed in write_pulses for\n") == EOF)
      exit(EOF);
    if (fprintf(stderr, "%s\n", outfile) == EOF)
      exit(EOF);
    return (EOF);
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<open_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xb0(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1080 <strcat@plt>
mov    $0xc8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1270 <open_files+0xf0>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
jne    1224 <open_files+0xa4>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rdi
call   10a0 <exit@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
jne    125e <open_files+0xde>
mov    0x2d92(%rip),%rax
mov    (%rax),%rdi
call   10a0 <exit@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    1322 <open_files+0x1a2>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1319 <open_files+0x199>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
jne    12cd <open_files+0x14d>
mov    0x2d23(%rip),%rax
mov    (%rax),%rdi
call   10a0 <exit@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cf9(%rip),%rcx
cmp    (%rcx),%rax
jne    1307 <open_files+0x187>
mov    0x2ce9(%rip),%rax
mov    (%rax),%rdi
call   10a0 <exit@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    1322 <open_files+0x1a2>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_files>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    $0xc8,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1090 <sprintf@plt>
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fb <open_files+0x7b>
mov    %rax,%rdi
call   1040 <fclose@plt>
lea    0xe26(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fb <open_files+0x7b>
mov    %rax,%rdi
call   1040 <fclose@plt>
jmp    123c <open_files+0xbc>
mov    0x2dd6(%rip),%rbx
mov    (%rbx),%edi
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dcf(%rip),%r15
cmp    (%r15),%rax
je     1249 <open_files+0xc9>
mov    (%rbx),%edi
lea    0xe0b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rax,%rdi
mov    (%r15),%rax
cmp    %rax,%rdi
je     124c <open_files+0xcc>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rax,%rdi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/best_tmp\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"File open failed in write_pulses for\0A\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @open_files(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [132 x i8]
store i8* %0, i8** %3
%7 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @malloc(i32 200)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
%16 = call i32 @sprintf(i8* %14, i8* %15)
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %40
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = call i64 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i64, i64* @EOF
%27 = call i32 @exit(i64 %26)
unreachable
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = call i64 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i64, i64* @EOF
%36 = call i32 @exit(i64 %35)
unreachable
37: ; preds = %28
%38 = load i64, i64* @EOF
%39 = trunc i64 %38 to i32
store i32 %39, i32* %2
br label %69
40: ; preds = %1
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** %4
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %5
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %66
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = call i64 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%49 = load i64, i64* @EOF
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i64, i64* @EOF
%53 = call i32 @exit(i64 %52)
unreachable
54: ; preds = %46
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %4
%57 = call i64 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = load i64, i64* @EOF
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i64, i64* @EOF
%62 = call i32 @exit(i64 %61)
unreachable
63: ; preds = %54
%64 = load i64, i64* @EOF
%65 = trunc i64 %64 to i32
store i32 %65, i32* %2
br label %69
66: ; preds = %40
%67 = load i32*, i32** %5
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %66, %63, %37
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
@.str = [10 x i8] c"/best_tmp\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"File open failed in write_pulses for\0A\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @open_files(i8* %0) {
%2 = alloca [132 x i8]
%3 = getelementptr inbounds [132 x i8], [132 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @malloc(i32 200)
%7 = inttoptr i64 %6 to i8*
%8 = call i32 @sprintf(i8* dereferenceable(1) %7, i8* %3)
%9 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %27
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i64 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @exit(i64 %13)
unreachable
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = call i64 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @exit(i64 %20)
unreachable
25: ; preds = %18
%26 = trunc i64 %21 to i32
br label %49
27: ; preds = %1
%28 = call i32 @fclose(i32* %9)
%29 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i64 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%34 = load i64, i64* @EOF
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @exit(i64 %33)
unreachable
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i64 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @exit(i64 %40)
unreachable
45: ; preds = %38
%46 = trunc i64 %41 to i32
br label %49
47: ; preds = %27
%48 = call i32 @fclose(i32* %29)
br label %49
49: ; preds = %47, %45, %25
%50 = phi i32 [ %26, %25 ], [ %46, %45 ], [ undef, %47 ]
ret i32 %50
}