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

/* Variables and functions */
int /*<<< orphan*/ conffile_free(struct conffile *);
struct conffile *conffile_new(int /*<<< orphan*/ *);
struct config *config_new(struct conffile *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct config *create_config(char *filename) {
  struct config *config;
  struct conffile *conffile;
  FILE *fp = fopen(filename, "r");
  if (!fp)
    return NULL;
  conffile = conffile_new(fp);
  if (!conffile)
    goto ferror;
  config = config_new(conffile, 0);
  if (!config)
    goto cnferror;
  return config;
ferror:
  fclose(fp);
  return NULL;
cnferror:
  conffile_free(conffile);
  return NULL;
}


x86 assembly (clang, -O0):
<create_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1188 <create_config+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <create_config+0xa8>
mov    -0x28(%rbp),%rdi
call   1050 <conffile_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a5 <create_config+0x55>
jmp    11d1 <create_config+0x81>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <config_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <create_config+0x74>
jmp    11e7 <create_config+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f8 <create_config+0xa8>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <create_config+0xa8>
mov    -0x20(%rbp),%rdi
call   1040 <conffile_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_config>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1199 <create_config+0x49>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <conffile_new@plt>
test   %rax,%rax
je     1191 <create_config+0x41>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <config_new@plt>
test   %rax,%rax
jne    119b <create_config+0x4b>
mov    %r14,%rdi
call   1040 <conffile_free@plt>
jmp    1199 <create_config+0x49>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.config = type { i32 }
%struct.conffile = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.config* @create_config(i8* %0) {
%2 = alloca %struct.config*
%3 = alloca i8*
%4 = alloca %struct.config*
%5 = alloca %struct.conffile*
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store %struct.config* null, %struct.config** %2
br label %32
12: ; preds = %1
%13 = load i32*, i32** %6
%14 = call %struct.conffile* @conffile_new(i32* %13)
store %struct.conffile* %14, %struct.conffile** %5
%15 = load %struct.conffile*, %struct.conffile** %5
%16 = icmp ne %struct.conffile* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
br label %26
18: ; preds = %12
%19 = load %struct.conffile*, %struct.conffile** %5
%20 = call %struct.config* @config_new(%struct.conffile* %19, i32 0)
store %struct.config* %20, %struct.config** %4
%21 = load %struct.config*, %struct.config** %4
%22 = icmp ne %struct.config* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
br label %29
24: ; preds = %18
%25 = load %struct.config*, %struct.config** %4
store %struct.config* %25, %struct.config** %2
br label %32
26: ; preds = %17
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
store %struct.config* null, %struct.config** %2
br label %32
29: ; preds = %23
%30 = load %struct.conffile*, %struct.conffile** %5
%31 = call i32 @conffile_free(%struct.conffile* %30)
store %struct.config* null, %struct.config** %2
br label %32
32: ; preds = %29, %26, %24, %11
%33 = load %struct.config*, %struct.config** %2
ret %struct.config* %33
}

LLVM IR (-O2):
%struct.config = type { i32 }
%struct.conffile = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.config* @create_config(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call %struct.conffile* @conffile_new(i32* %2)
%6 = icmp eq %struct.conffile* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call %struct.config* @config_new(%struct.conffile* %5, i32 0)
%9 = icmp eq %struct.config* %8, null
br i1 %9, label %12, label %14
10: ; preds = %4
%11 = tail call i32 @fclose(i32* %2)
br label %14
12: ; preds = %7
%13 = tail call i32 @conffile_free(%struct.conffile* %5)
br label %14
14: ; preds = %7, %1, %12, %10
%15 = phi %struct.config* [ null, %12 ], [ null, %10 ], [ null, %1 ], [ %8, %7 ]
ret %struct.config* %15
}