#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*/ dbg_time(char *, char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
scalar_t__ strcmp(char *, char const *);
int is_same_linkfile(const char *dir, const char *file, void *argv[]) {
  const char *qmichannel = (const char *)argv[1];
  char linkname[256];
  char filename[256];
  int linksize;
  snprintf(linkname, 256, "%s/%s", dir, file);
  linksize = readlink(linkname, filename, 256);
  if (linksize <= 0)
    return 0;
  filename[linksize] = 0;
  if (strcmp(filename, qmichannel))
    return 0;
  dbg_time("%s -> %s", linkname, filename);
  return 1;
}


x86 assembly (clang, -O0):
<is_same_linkfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x100,%esi
lea    0xe82(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x130(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    $0x100,%edx
call   1030 <readlink@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0x0,-0x234(%rbp)
jg     11ba <is_same_linkfile+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    1210 <is_same_linkfile+0xd0>
movslq -0x234(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ef <is_same_linkfile+0xaf>
movl   $0x0,-0x4(%rbp)
jmp    1210 <is_same_linkfile+0xd0>
lea    -0x130(%rbp),%rsi
lea    -0x230(%rbp),%rdx
lea    0xe02(%rip),%rdi
call   1040 <dbg_time@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_same_linkfile>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r8
mov    %rdi,%rcx
mov    0x8(%rdx),%rbx
lea    0xea6(%rip),%rdx
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0x100,%edx
call   1030 <readlink@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    11b7 <is_same_linkfile+0x77>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b7 <is_same_linkfile+0x77>
lea    0xe64(%rip),%rdi
lea    0x100(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <dbg_time@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [9 x i8] c"%s -> %s\00"
define i32 @is_same_linkfile(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%12 = load i8**, i8*** %7
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %8
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%21 = call i32 @readlink(i8* %19, i8* %20, i32 256)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 0, i32* %4
br label %38
25: ; preds = %3
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%30 = load i8*, i8** %8
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 0, i32* %4
br label %38
34: ; preds = %25
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%37 = call i32 @dbg_time(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %36)
store i32 1, i32* %4
br label %38
38: ; preds = %34, %33, %24
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [9 x i8] c"%s -> %s\00"
define i32 @is_same_linkfile(i8* %0, i8* %1, i8** nocapture %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds i8*, i8** %2, i64 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = call i32 @readlink(i8* %8, i8* %9, i32 256)
%12 = icmp slt i32 %11, 1
br i1 %12, label %20, label %13
13: ; preds = %3
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i64 @strcmp(i8* %9, i8* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @dbg_time(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %9)
br label %20
20: ; preds = %13, %3, %18
%21 = phi i32 [ 1, %18 ], [ 0, %3 ], [ 0, %13 ]
ret i32 %21
}