#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 {
  unsigned int s_addr;
};

/* Variables and functions */
scalar_t__ ERANGE;
unsigned int ULONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
unsigned int htonl(unsigned int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <hex>\n", argv[0]);
    return -1;
  }
  unsigned int host = strtoul(argv[1], NULL, 0);
  if (host == ULONG_MAX && errno == ERANGE) {
    perror("strtoul");
    return -1;
  }
  unsigned int net = htonl(host);
  struct in_addr in;
  in.s_addr = net;
  char *decimal = inet_ntoa(in);
  printf("%s\n", decimal);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
jne    1202 <main+0xa2>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
jne    1202 <main+0xa2>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <main+0xd6>
mov    -0x14(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11b5 <main+0x55>
mov    0x8(%rsi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <main+0x36>
mov    0x2e49(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e57(%rip),%rdx
cmp    (%rdx),%rcx
je     11d6 <main+0x76>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,%edi
call   1030 <inet_ntoa@plt>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    11d2 <main+0x72>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
jmp    11cd <main+0x6d>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s <hex>\0A\00"
@ULONG_MAX = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [8 x i8] c"strtoul\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.in_addr
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %42
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtoul(i8* %21, i32* null, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* @ULONG_MAX
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = load i64, i64* @errno
%28 = load i64, i64* @ERANGE
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
32: ; preds = %26, %18
%33 = load i32, i32* %6
%34 = call i32 @htonl(i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i8* @inet_ntoa(i32 %38)
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %32, %30, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s <hex>\0A\00"
@ULONG_MAX = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [8 x i8] c"strtoul\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %24
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strtoul(i8* nocapture %10, i32* null, i32 0)
%12 = load i32, i32* @ULONG_MAX
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i64, i64* @errno
%16 = load i64, i64* @ERANGE
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %14, %8
%21 = tail call i32 @htonl(i32 %11)
%22 = tail call i8* @inet_ntoa(i32 %21)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %18, %20, %4
%25 = phi i32 [ -1, %4 ], [ -1, %18 ], [ 0, %20 ]
ret i32 %25
}