#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 */
struct hostent {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int ERANGE;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int NETDB_INTERNAL;
int gethostbyname_r(char *, struct hostent *, char *, int, struct hostent **,
                    int *);
int do_test(void) {
  char buf[32];
  struct hostent *result = NULL;
  struct hostent ret;
  int h_err = 0;
  int err;
  err = gethostbyname_r("1.2.3.4", &ret, buf, sizeof(buf), &result, &h_err);
  return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x20(%rbp),%rdx
lea    0xece(%rip),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%ecx
lea    -0x28(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1030 <gethostbyname_r@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <do_test+0x70>
mov    -0x34(%rbp),%eax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <do_test+0x70>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    118c <do_test+0x7c>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
sub    $0x48,%rsp
movq   $0x0,0x18(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xed4(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%r8
lea    0xc(%rsp),%r9
mov    $0x20,%ecx
call   1030 <gethostbyname_r@plt>
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%eax
jne    116d <do_test+0x5d>
mov    0xc(%rsp),%eax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
jne    116d <do_test+0x5d>
mov    0x2e5d(%rip),%rax
jmp    1174 <do_test+0x64>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@.str = [8 x i8] c"1.2.3.4\00"
@ERANGE = global i32 0
@NETDB_INTERNAL = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @do_test() {
%1 = alloca [32 x i8]
%2 = alloca %struct.hostent*
%3 = alloca %struct.hostent
%4 = alloca i32
%5 = alloca i32
store %struct.hostent* null, %struct.hostent** %2
store i32 0, i32* %4
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%7 = call i32 @gethostbyname_r(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.hostent* %3, i8* %6, i32 32, %struct.hostent** %2, i32* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load i32, i32* @ERANGE
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i32, i32* %4
%13 = load i32, i32* @NETDB_INTERNAL
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* @EXIT_SUCCESS
br label %19
17: ; preds = %11, %0
%18 = load i32, i32* @EXIT_FAILURE
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
ret i32 %20
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@.str = [8 x i8] c"1.2.3.4\00"
@ERANGE = global i32 0
@NETDB_INTERNAL = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @do_test() {
%1 = alloca [32 x i8]
%2 = alloca %struct.hostent*
%3 = alloca %struct.hostent
%4 = alloca i32
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.hostent** %2 to i8*
store %struct.hostent* null, %struct.hostent** %2
%7 = bitcast %struct.hostent* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = call i32 @gethostbyname_r(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %struct.hostent* %3, i8* %5, i32 32, %struct.hostent** %2, i32* %4)
%10 = load i32, i32* @ERANGE
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* %4
%14 = load i32, i32* @NETDB_INTERNAL
%15 = icmp eq i32 %13, %14
br i1 %15, label %17, label %16
16: ; preds = %12, %0
br label %17
17: ; preds = %12, %16
%18 = phi i32* [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %12 ]
%19 = load i32, i32* %18
ret i32 %19
}