#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 */

/* Variables and functions */
int /*<<< orphan*/ close_fd(char const *, int);
int open_input_fd(char const *);
int /*<<< orphan*/ printf(char *, char const *);
void open_close_input_fd(const char *input_path) {
  int fi = open_input_fd(input_path);
  printf("open(%s) input OK\n", input_path);
  close_fd(input_path, fi);
  printf("close(%s) input OK\n", input_path);
  int f1 = open_input_fd(input_path);
  printf("open(%s) input 1 OK\n", input_path);
  int f2 = open_input_fd(input_path);
  printf("open(%s) input 2 OK\n", input_path);
  close_fd(input_path, f1);
  printf("close(%s) input 1 OK\n", input_path);
  close_fd(input_path, f2);
  printf("close(%s) input 2 OK\n", input_path);
}


x86 assembly (clang, -O0):
<open_close_input_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <open_input_fd@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <close_fd@plt>
mov    -0x8(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <open_input_fd@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <open_input_fd@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <close_fd@plt>
mov    -0x8(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <close_fd@plt>
mov    -0x8(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_close_input_fd>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <open_input_fd@plt>
mov    %eax,%ebp
lea    0xebb(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <close_fd@plt>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <open_input_fd@plt>
mov    %eax,%ebp
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <open_input_fd@plt>
mov    %eax,%r14d
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <close_fd@plt>
lea    0xea7(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <close_fd@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"open(%s) input OK\0A\00"
@.str.1 = [20 x i8] c"close(%s) input OK\0A\00"
@.str.2 = [21 x i8] c"open(%s) input 1 OK\0A\00"
@.str.3 = [21 x i8] c"open(%s) input 2 OK\0A\00"
@.str.4 = [22 x i8] c"close(%s) input 1 OK\0A\00"
@.str.5 = [22 x i8] c"close(%s) input 2 OK\0A\00"
define void @open_close_input_fd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @open_input_fd(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = call i32 @close_fd(i8* %10, i32 %11)
%13 = load i8*, i8** %2
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i32 @open_input_fd(i8* %15)
store i32 %16, i32* %4
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %2
%20 = call i32 @open_input_fd(i8* %19)
store i32 %20, i32* %5
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = call i32 @close_fd(i8* %23, i32 %24)
%26 = load i8*, i8** %2
%27 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %2
%29 = load i32, i32* %5
%30 = call i32 @close_fd(i8* %28, i32 %29)
%31 = load i8*, i8** %2
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %31)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"open(%s) input OK\0A\00"
@.str.1 = [20 x i8] c"close(%s) input OK\0A\00"
@.str.2 = [21 x i8] c"open(%s) input 1 OK\0A\00"
@.str.3 = [21 x i8] c"open(%s) input 2 OK\0A\00"
@.str.4 = [22 x i8] c"close(%s) input 1 OK\0A\00"
@.str.5 = [22 x i8] c"close(%s) input 2 OK\0A\00"
define void @open_close_input_fd(i8* %0) {
%2 = tail call i32 @open_input_fd(i8* %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @close_fd(i8* %0, i32 %2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = tail call i32 @open_input_fd(i8* %0)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%8 = tail call i32 @open_input_fd(i8* %0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%10 = tail call i32 @close_fd(i8* %0, i32 %6)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%12 = tail call i32 @close_fd(i8* %0, i32 %8)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %0)
ret void
}