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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in_addr *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char **argv) {
  struct in_addr inAddr;
  uint32_t addr;
  char dst[8192];
  if (argc != 2) {
    fprintf(stderr, "usage: %s <hex number>\n", argv[0]);
    exit(0);
  }
  sscanf(argv[1], "%x", &addr);
  inAddr.s_addr = htonl(addr);
  if (!inet_ntop(AF_INET, &inAddr, dst, 8192)) {
    fprintf(stderr, "%s: %s\n", "error", strerror(-1));
    exit(0);
  }
  printf("%s\n", dst);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0x2000,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%eax
jne    1240 <main+0xd0>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2024(%rbp)
mov    $0xffffffff,%edi
call   1090 <strerror@plt>
mov    -0x2024(%rbp),%edi
mov    %rax,%rcx
lea    0xdf0(%rip),%rsi
lea    0xdf1(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x2020(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2010,%rsp
cmp    $0x2,%edi
jne    11dc <main+0x6c>
mov    0x8(%rsi),%rdi
lea    0xe90(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
mov    0xc(%rsp),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    $0x2000,%ecx
call   1030 <inet_ntop@plt>
test   %eax,%eax
je     11fd <main+0x8d>
lea    0xe58(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2010,%rsp
pop    %rbx
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe11(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%ebx
mov    $0xffffffff,%edi
call   1090 <strerror@plt>
lea    0xe04(%rip),%rsi
lea    0xe05(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <hex number>\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@AF_INET = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [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 %struct.in_addr
%7 = alloca i32
%8 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%23 = load i32, i32* %7
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%28 = call i32 @inet_ntop(i32 %26, %struct.in_addr* %6, i8* %27, i32 8192)
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %18
%31 = load i32, i32* @stderr
%32 = call i8* @strerror(i32 -1)
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %18
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %36)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <hex number>\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@AF_INET = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = alloca i32
%5 = alloca [8192 x i8]
%6 = bitcast %struct.in_addr* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %4
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = call i32 @inet_ntop(i32 %22, %struct.in_addr* %3, i8* %8, i32 8192)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i8* @strerror(i32 -1)
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %15
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
ret i32 0
}