#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int inet_aton(char *, struct in_addr *);
unsigned int ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <addr>\n", argv[0]);
    return -1;
  }
  struct in_addr net;
  int ret = inet_aton(argv[1], &net);
  if (ret == 0) {
    fprintf(stderr, "inet_aton: convert %s failed\n", argv[1]);
    return -1;
  }
  unsigned int host = ntohl(net.s_addr);
  printf("0x%x\n", host);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <inet_aton@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11cf <main+0x8f>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <main+0xb0>
mov    -0x18(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    117a <main+0x3a>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1050 <inet_aton@plt>
test   %eax,%eax
je     118f <main+0x4f>
mov    0x8(%rsp),%edi
call   1060 <ntohl@plt>
lea    0xec1(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11ad <main+0x6d>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe73(%rip),%rsi
jmp    11a3 <main+0x63>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"usage: %s <addr>\0A\00"
@.str.1 = [30 x i8] c"inet_aton: convert %s failed\0A\00"
@.str.2 = [6 x i8] c"0x%x\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 i32
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 %17
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 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %36
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @inet_aton(i8* %20, %struct.in_addr* %6)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 -1, i32* %3
br label %36
30: ; preds = %17
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @ntohl(i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %34)
store i32 0, i32* %3
br label %36
36: ; preds = %30, %24, %11
%37 = load i32, i32* %3
ret i32 %37
}

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