#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 */
struct config_data {
  int dummy;
};
typedef int int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ debugf(char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int32_t read_badcw(struct config_data *cfg) {
  FILE *fhandle;
  char fname[512];
  int32_t chncount = 0;
  sprintf(fname, "/var/etc/badcw.cfg");
  fhandle = fopen(fname, "rt");
  if (fhandle == 0) {
    debugf(" config: parsing file '%s'\n", fname);
    return -1;
  }
  fclose(fhandle);
  debugf(" config: reading %d badcw.cfg.\n", chncount);
  return 0;
}


x86 assembly (clang, -O0):
<read_badcw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x220(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11af <read_badcw+0x6f>
lea    -0x220(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <debugf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <read_badcw+0x93>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x224(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <debugf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_badcw>:
push   %rbx
sub    $0x200,%rsp
movups 0xec1(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x676663,0xf(%rsp)
lea    0xec1(%rip),%rsi
mov    %rsp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     117b <read_badcw+0x4b>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xec4(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %eax,%eax
call   1040 <debugf@plt>
jmp    1191 <read_badcw+0x61>
lea    0xe94(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <debugf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.config_data = type { i32 }
@.str = [19 x i8] c"/var/etc/badcw.cfg\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [28 x i8] c" config: parsing file '%s'\0A\00"
@.str.3 = [32 x i8] c" config: reading %d badcw.cfg.\0A\00"
define i32 @read_badcw(%struct.config_data* %0) {
%2 = alloca i32
%3 = alloca %struct.config_data*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca i32
store %struct.config_data* %0, %struct.config_data** %3
store i32 0, i32* %6
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = call i32 (i8*, ...) @debugf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32 -1, i32* %2
br label %21
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @debugf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %19)
store i32 0, i32* %2
br label %21
21: ; preds = %16, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.config_data = type { i32 }
@.str = [19 x i8] c"/var/etc/badcw.cfg\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [28 x i8] c" config: parsing file '%s'\0A\00"
@.str.3 = [32 x i8] c" config: reading %d badcw.cfg.\0A\00"
define i32 @read_badcw(%struct.config_data* nocapture readnone %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @debugf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %11
8: ; preds = %1
%9 = tail call i32 @fclose(i32* %4)
%10 = tail call i32 (i8*, ...) @debugf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %12
}