#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*/ LOG_io(char *, char *);
int /*<<< orphan*/ errno;
scalar_t__ readlink(char *, char *, int);
char *strerror(int /*<<< orphan*/);
void hello() {
  char buf[1024];
  int k = (int)readlink("/proc/self/fd/2", buf, 1023);
  if (k < 0)
    LOG_io("ioprc started, /proc/self/fd/2: %s", strerror(errno));
  else
    buf[k] = 0, LOG_io("ioprc started, logfile is \"%s\"", buf);
}


x86 assembly (clang, -O0):
<hello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x400(%rbp),%rsi
lea    0xeb7(%rip),%rdi
mov    $0x3ff,%edx
call   1030 <readlink@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x0,-0x404(%rbp)
jge    1188 <hello+0x58>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe92(%rip),%rdi
call   1040 <LOG_io@plt>
jmp    11aa <hello+0x7a>
movslq -0x404(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1040 <LOG_io@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hello>:
sub    $0x408,%rsp
lea    0xec2(%rip),%rdi
mov    %rsp,%rsi
mov    $0x3ff,%edx
call   1030 <readlink@plt>
test   $0x80000000,%eax
jne    116f <hello+0x3f>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xed4(%rip),%rdi
mov    %rsp,%rsi
call   1040 <LOG_io@plt>
add    $0x408,%rsp
ret
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
add    $0x408,%rsp
jmp    1040 <LOG_io@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/self/fd/2\00"
@.str.1 = [35 x i8] c"ioprc started, /proc/self/fd/2: %s\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"ioprc started, logfile is \22%s\22\00"
define void @hello() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = call i64 @readlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3, i32 1023)
%5 = trunc i64 %4 to i32
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @LOG_io(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %18
12: ; preds = %0
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%17 = call i32 @LOG_io(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/self/fd/2\00"
@.str.1 = [35 x i8] c"ioprc started, /proc/self/fd/2: %s\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"ioprc started, logfile is \22%s\22\00"
define void @hello() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i64 @readlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %2, i32 1023)
%4 = and i64 %3, 2147483648
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @LOG_io(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %15
10: ; preds = %0
%11 = shl i64 %3, 32
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @LOG_io(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %15
15: ; preds = %10, %6
ret void
}