#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 */
typedef int /*<<< orphan*/ errstr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/, char *);
int /*<<< orphan*/ strerror_r(int /*<<< orphan*/, char *, int);
void *thr3(void *v) {
  char errstr[128];
  FILE *f = fopen("bogus3", "r");
  strerror_r(errno, errstr, sizeof(errstr));
  printf("f  = %ld, errno  = %d (%s)\n", (long)f, errno, errstr);
  return NULL;
}


x86 assembly (clang, -O0):
<thr3>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x98(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <strerror_r@plt>
mov    -0x98(%rbp),%rsi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
lea    -0x90(%rbp),%rcx
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr3>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xebd(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    0x2e87(%rip),%r15
mov    (%r15),%edi
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0x80,%edx
call   1040 <strerror_r@plt>
mov    (%r15),%edx
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rcx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"bogus3\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"f = %ld, errno = %d (%s)\0A\00"
define i8* @thr3(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32, i32* @errno
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = call i32 @strerror_r(i32 %6, i8* %7, i32 128)
%9 = load i32*, i32** %4
%10 = ptrtoint i32* %9 to i64
%11 = load i32, i32* @errno
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %10, i32 %11, i8* %12)
ret i8* null
}

LLVM IR (-O2):
@.str = [7 x i8] c"bogus3\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"f = %ld, errno = %d (%s)\0A\00"
define noalias i8* @thr3(i8* nocapture readnone %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @errno
%6 = call i32 @strerror_r(i32 %5, i8* %3, i32 128)
%7 = ptrtoint i32* %4 to i64
%8 = load i32, i32* @errno
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %7, i32 %8, i8* %3)
ret i8* null
}