#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 control {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int control_parsefd(int, struct control **);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int control_parse(const char *path, struct control **ctrl) {
  int fd, ret;
  if ((fd = open(path, O_RDONLY)) < 0) {
    perror("control_parse: open failed");
    return -1;
  }
  ret = control_parsefd(fd, ctrl);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<control_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1186 <control_parse+0x46>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <control_parse+0x63>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <control_parsefd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<control_parse>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1176 <control_parse+0x36>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <control_parsefd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    116f <control_parse+0x2f>

LLVM IR (-O0):
%struct.control = type { i32 }
@O_RDONLY = global i32 0
@.str = [27 x i8] c"control_parse: open failed\00"
define i32 @control_parse(i8* %0, %struct.control** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.control**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store %struct.control** %1, %struct.control*** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load %struct.control**, %struct.control*** %5
%17 = call i32 @control_parsefd(i32 %15, %struct.control** %16)
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %7
store i32 %20, i32* %3
br label %21
21: ; preds = %14, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.control = type { i32 }
@O_RDONLY = global i32 0
@.str = [27 x i8] c"control_parse: open failed\00"
define i32 @control_parse(i8* nocapture %0, %struct.control** %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = tail call i32 @control_parsefd(i32 %4, %struct.control** %1)
%10 = tail call i32 @close(i32 %4)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ %9, %8 ]
ret i32 %12
}