#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 /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, struct in_addr *, char *,
                              int);
int inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main() {
  char str[128];
  struct in_addr addr;
  int ret = inet_pton(AF_INET, "127.0.0.1", &addr);
  if (ret == -1) {
    perror("inet_pton");
    exit(1);
  }
  if (ret == 0) {
    puts("badly formatted string");
    exit(2);
  }
  if (inet_ntop(AF_INET, &addr, str, sizeof(str)) == NULL) {
    perror("inet_ntop");
    exit(1);
  }
  printf("%s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
lea    -0x98(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0xffffffff,-0x9c(%rbp)
jne    11b7 <main+0x57>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x9c(%rbp)
jne    11da <main+0x7a>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    -0x98(%rbp),%rsi
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    121b <main+0xbb>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x90(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x90,%rsp
mov    0x2e79(%rip),%rbx
mov    (%rbx),%edi
lea    0xe88(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <inet_pton@plt>
test   %eax,%eax
je     11c2 <main+0x62>
cmp    $0xffffffff,%eax
je     11d8 <main+0x78>
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     11e1 <main+0x81>
lea    0xe88(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
ret
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe2b(%rip),%rdi
jmp    11e8 <main+0x88>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [10 x i8] c"inet_pton\00"
@.str.2 = [23 x i8] c"badly formatted string\00"
@.str.3 = [10 x i8] c"inet_ntop\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca %struct.in_addr
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = call i32 @inet_pton(i32 %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %12
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = call i32* @inet_ntop(i32 %19, %struct.in_addr* %3, i8* %20, i32 128)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [10 x i8] c"inet_pton\00"
@.str.2 = [23 x i8] c"badly formatted string\00"
@.str.3 = [10 x i8] c"inet_ntop\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca %struct.in_addr
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.in_addr* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = call i32 @inet_pton(i32 %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %2)
switch i32 %6, label %13 [
i32 -1, label %7
i32 0, label %10
]
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 2)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = call i32* @inet_ntop(i32 %14, %struct.in_addr* %2, i8* %3, i32 128)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
ret i32 0
}