#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 in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ htonl(unsigned int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, unsigned int, char *, char *, char const *);
int strcmp(char *, char const *);
int test(unsigned int inaddr, const char *expected) {
  struct in_addr addr;
  char *res;
  int fail;
  addr.s_addr = htonl(inaddr);
  res = inet_ntoa(addr);
  fail = strcmp(res, expected);
  printf("%#010x -> \"%s\" -> %s%s\n", inaddr, res,
         fail ? "fail, expected" : "ok", fail ? expected : "");
  return fail;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edx
lea    0xe99(%rip),%rax
lea    0xe83(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b7 <test+0x77>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <test+0x87>
lea    0xe59(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <test+0x87>
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%r8
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
call   1050 <htonl@plt>
mov    %eax,%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
mov    %eax,%ebx
test   %eax,%eax
lea    0xeb5(%rip),%rax
lea    0xe9f(%rip),%rcx
cmove  %rax,%rcx
lea    0xe93(%rip),%r8
cmovne %r15,%r8
lea    0xe71(%rip),%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [24 x i8] c"%x -> \22%s\22 -> %s%s\0A\00"
@.str.1 = [15 x i8] c"fail, expected\00"
@.str.2 = [3 x i8] c"ok\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @test(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.in_addr
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* %3
%9 = call i32 @htonl(i32 %8)
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i8* @inet_ntoa(i32 %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = load i8*, i8** %4
%16 = call i32 @strcmp(i8* %14, i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %3
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = load i8*, i8** %4
br label %28
27: ; preds = %2
br label %28
28: ; preds = %27, %25
%29 = phi i8* [ %26, %25 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %27 ]
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %18, i8* %22, i8* %29)
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@.str = [24 x i8] c"%x -> \22%s\22 -> %s%s\0A\00"
@.str.1 = [15 x i8] c"fail, expected\00"
@.str.2 = [3 x i8] c"ok\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @test(i32 %0, i8* %1) {
%3 = tail call i32 @htonl(i32 %0)
%4 = tail call i8* @inet_ntoa(i32 %3)
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(1) %1)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0)
%8 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %4, i8* %7, i8* %8)
ret i32 %5
}