#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 close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
int /*<<< orphan*/ stdout;
char *strrchr(char *, char);
int my_close(int fd) {
  fprintf(
      stdout,
      "[%s:%d] "
      "in my close, fd is 0x%x"
      "\n",
      strrchr(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/heads/master/main.c",
          '/') > 0
          ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/"
                    "heads/master/main.c",
                    '/') +
                1
          : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/heads/master/"
            "main.c",
      304, fd);
  ;
  if (fd == 0x66) {
    fprintf(stdout,
            "[%s:%d] "
            "magic close requested"
            "\n",
            strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/"
                    "heads/master/main.c",
                    '/') > 0
                ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/m1m1x/"
                          "memdlopen/refs/heads/master/main.c",
                          '/') +
                      1
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/"
                  "heads/master/main.c",
            306);
    ;
    return 0;
  }
  return close(fd);
}


x86 assembly (clang, -O0):
<my_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
jbe    1180 <my_close+0x50>
lea    0xeb8(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1190 <my_close+0x60>
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1190 <my_close+0x60>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%r8d
lea    0xe5e(%rip),%rsi
mov    $0x130,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x66,-0x8(%rbp)
jne    1233 <my_close+0x103>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe56(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
jbe    11fd <my_close+0xcd>
lea    0xe3b(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120d <my_close+0xdd>
lea    0xe1d(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    120d <my_close+0xdd>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rdx
lea    0xe89(%rip),%rsi
mov    $0x132,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123e <my_close+0x10e>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_close>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb3(%rip),%r14
mov    (%r14),%edi
lea    0xec9(%rip),%rsi
lea    0xf5f(%rip),%rdx
mov    $0x130,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x66,%ebx
jne    1179 <my_close+0x59>
mov    (%r14),%edi
lea    0xf48(%rip),%rsi
lea    0xf3a(%rip),%rdx
mov    $0x132,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <close@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [33 x i8] c"[%s:%d] in my close, fd is 0x%x\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/heads/master/main.c\00"
@.str.2 = [31 x i8] c"[%s:%d] magic close requested\0A\00"
define i32 @my_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* @stdout
%5 = call i8* @strrchr(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%6 = icmp ugt i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i8* @strrchr(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%9 = getelementptr inbounds i8, i8* %8, i64 1
br label %11
10: ; preds = %1
br label %11
11: ; preds = %10, %7
%12 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), %10 ]
%13 = load i32, i32* %3
%14 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %12, i32 304, i32 %13)
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 102
br i1 %16, label %17, label %28
17: ; preds = %11
%18 = load i32, i32* @stdout
%19 = call i8* @strrchr(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%20 = icmp ugt i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i8* @strrchr(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i8 signext 47)
%23 = getelementptr inbounds i8, i8* %22, i64 1
br label %25
24: ; preds = %17
br label %25
25: ; preds = %24, %21
%26 = phi i8* [ %23, %21 ], [ getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), %24 ]
%27 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32 306)
store i32 0, i32* %2
br label %31
28: ; preds = %11
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [33 x i8] c"[%s:%d] in my close, fd is 0x%x\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/m1m1x/memdlopen/refs/heads/master/main.c\00"
@.str.2 = [31 x i8] c"[%s:%d] magic close requested\0A\00"
define i32 @my_close(i32 %0) {
%2 = load i32, i32* @stdout
%3 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 124), i32 304, i32 %0)
%4 = icmp eq i32 %0, 102
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stdout
%7 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 124), i32 306)
br label %10
8: ; preds = %1
%9 = tail call i32 @close(i32 %0)
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ 0, %5 ], [ %9, %8 ]
ret i32 %11
}