#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, 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) {
  struct in_addr pin;
  if (argc != 2) {
    printf("%d\n", argc);
    fprintf(stderr, "Usage: inet_aton dotted-quad\n");
    exit(1);
  }
  int valid = inet_aton(argv[1], &pin);
  if (!valid) {
    fprintf(stderr, "inet_aton could not parse \"%s\"\n", argv[1]);
    exit(1);
  }
  unsigned int address = ntohl(pin.s_addr);
  unsigned int octet1 = (0xff000000 & address) >> 24;
  unsigned int octet2 = (0x00ff0000 & address) >> 16;
  unsigned int octet3 = (0x0000ff00 & address) >> 8;
  unsigned int octet4 = 0x000000ff & address;
  printf("ping %u.%u.%u.%u\n", octet1, octet2, octet3, octet4);
  printf("ping %u.%u.%u\n", octet1, octet2, (octet3 << 8) + octet4);
  printf("ping %u.%u\n", octet1, (octet2 << 16) + (octet3 << 8) + octet4);
  printf("ping %u\n", address);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     119b <main+0x4b>
mov    -0x4(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
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    11e2 <main+0x92>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <ntohl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
shl    $0x8,%ecx
add    -0x30(%rbp),%ecx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
shl    $0x10,%edx
mov    -0x2c(%rbp),%eax
shl    $0x8,%eax
add    %eax,%edx
add    -0x30(%rbp),%edx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    120b <main+0xbb>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1050 <inet_aton@plt>
test   %eax,%eax
je     123c <main+0xec>
mov    0x8(%rsp),%edi
call   1070 <ntohl@plt>
mov    %eax,%ebx
mov    %eax,%r15d
shr    $0x18,%r15d
shr    $0x10,%eax
movzbl %al,%ebp
movzbl %bh,%ecx
movzbl %bl,%r14d
lea    0xe9e(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ecx,%r12d
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
shl    $0x8,%r12d
movzwl %bx,%ecx
lea    0xe90(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
shl    $0x10,%ebp
or     %r12d,%ebp
or     %r14d,%ebp
lea    0xe83(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%esi
lea    0xdec(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Usage: inet_aton dotted-quad\0A\00"
@.str.2 = [32 x i8] c"inet_aton could not parse \22%s\22\0A\00"
@.str.3 = [18 x i8] c"ping %u.%u.%u.%u\0A\00"
@.str.4 = [15 x i8] c"ping %u.%u.%u\0A\00"
@.str.5 = [12 x i8] c"ping %u.%u\0A\00"
@.str.6 = [9 x i8] c"ping %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.in_addr
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* %3
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @inet_aton(i8* %23, %struct.in_addr* %5)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %20
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @ntohl(i32 %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = and i32 -16777216, %38
%40 = lshr i32 %39, 24
store i32 %40, i32* %8
%41 = load i32, i32* %7
%42 = and i32 16711680, %41
%43 = lshr i32 %42, 16
store i32 %43, i32* %9
%44 = load i32, i32* %7
%45 = and i32 65280, %44
%46 = lshr i32 %45, 8
store i32 %46, i32* %10
%47 = load i32, i32* %7
%48 = and i32 255, %47
store i32 %48, i32* %11
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = shl i32 %56, 8
%58 = load i32, i32* %11
%59 = add i32 %57, %58
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %55, i32 %59)
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = shl i32 %62, 16
%64 = load i32, i32* %10
%65 = shl i32 %64, 8
%66 = add i32 %63, %65
%67 = load i32, i32* %11
%68 = add i32 %66, %67
%69 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %61, i32 %68)
%70 = load i32, i32* %7
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %70)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Usage: inet_aton dotted-quad\0A\00"
@.str.2 = [32 x i8] c"inet_aton could not parse \22%s\22\0A\00"
@.str.3 = [18 x i8] c"ping %u.%u.%u.%u\0A\00"
@.str.4 = [15 x i8] c"ping %u.%u.%u\0A\00"
@.str.5 = [12 x i8] c"ping %u.%u\0A\00"
@.str.6 = [9 x i8] c"ping %u\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = bitcast %struct.in_addr* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @inet_aton(i8* %13, %struct.in_addr* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @ntohl(i32 %23)
%25 = lshr i32 %24, 24
%26 = lshr i32 %24, 16
%27 = and i32 %26, 255
%28 = lshr i32 %24, 8
%29 = and i32 %28, 255
%30 = and i32 %24, 255
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %27, i32 %29, i32 %30)
%32 = shl nuw nsw i32 %29, 8
%33 = and i32 %24, 65535
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %25, i32 %27, i32 %33)
%35 = shl nuw nsw i32 %27, 16
%36 = or i32 %35, %32
%37 = or i32 %36, %30
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %37)
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %24)
ret i32 0
}