#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 dummy;
};
typedef int in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ basename(char *);
scalar_t__ inet_aton(char *, struct in_addr *);
int inet_network(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    return -1;
  } else if (strcmp(basename(argv[0]), "inet_aton") == 0) {
    in_addr_t addr = inet_network(argv[1]);
    printf("0x%08x\n", addr);
    return addr == -1 ? 1 : 0;
  } else {
    struct in_addr addr;
    if (inet_aton(argv[1], &addr)) {
      printf("%s\n", inet_ntoa(addr));
      return 0;
    } else {
    }
    return 2;
  }
}


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)
jge    118c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <basename@plt>
mov    %eax,%edi
lea    0xe5f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <inet_network@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xffffffff,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1235 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <inet_aton@plt>
cmp    $0x0,%rax
je     1229 <main+0xc9>
mov    -0x18(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1235 <main+0xd5>
jmp    122e <main+0xce>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jl     11ef <main+0x7f>
mov    %rsi,%rbx
mov    (%rsi),%rdi
call   1080 <basename@plt>
lea    0xe6f(%rip),%rsi
mov    %eax,%edi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11c5 <main+0x55>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1090 <inet_aton@plt>
test   %rax,%rax
je     11ea <main+0x7a>
mov    0x8(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11ef <main+0x7f>
mov    0x8(%rbx),%rdi
call   1040 <inet_network@plt>
mov    %eax,%ebx
lea    0xe33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
sete   %al
jmp    11ef <main+0x7f>
mov    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [10 x i8] c"inet_aton\00"
@.str.1 = [8 x i8] c"0x%08x\0A\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 %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %42
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @basename(i8* %14)
%16 = call i64 @strcmp(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @inet_network(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
store i32 %28, i32* %3
br label %42
29: ; preds = %11
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @inet_aton(i8* %32, %struct.in_addr* %7)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i8* @inet_ntoa(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
store i32 0, i32* %3
br label %42
40: ; preds = %29
br label %41
41: ; preds = %40
store i32 2, i32* %3
br label %42
42: ; preds = %41, %35, %18, %10
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [10 x i8] c"inet_aton\00"
@.str.1 = [8 x i8] c"0x%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = icmp slt i32 %0, 2
br i1 %4, label %30, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @basename(i8* %6)
%8 = tail call i64 @strcmp(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @inet_network(i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %13, -1
%16 = zext i1 %15 to i32
br label %30
17: ; preds = %5
%18 = bitcast %struct.in_addr* %3 to i8*
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @inet_aton(i8* %20, %struct.in_addr* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
%27 = call i32 @puts(i8* dereferenceable(1) %26)
br label %28
28: ; preds = %17, %23
%29 = phi i32 [ 0, %23 ], [ 2, %17 ]
br label %30
30: ; preds = %2, %28, %10
%31 = phi i32 [ %16, %10 ], [ %29, %28 ], [ -1, %2 ]
ret i32 %31
}