#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ in;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *sock_ntop(struct sockaddr *, int);
int main(void) {
  char *str;
  struct sockaddr_in in;
  in.sin_family = AF_INET;
  in.sin_port = htons(12345);
  if (inet_pton(AF_INET, "192.168.1.88", &in.sin_addr) <= 0) {
    perror("inet_pton: AF_INET error");
    return 1;
  }
  if ((str = sock_ntop((struct sockaddr *)&in, sizeof(in))) == NULL) {
    perror("sock_ntop error");
    return 1;
  }
  printf("after sock_ntop: str = %s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x3039,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
jg     11b3 <main+0x63>
lea    0xe6b(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xae>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1050 <sock_ntop@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e7 <main+0x97>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1040 <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    0x2e8c(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x3039,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe87(%rip),%rsi
mov    %rsp,%rdx
call   1060 <inet_pton@plt>
test   %rax,%rax
jle    11af <main+0x5f>
mov    %rsp,%rdi
mov    $0xc,%esi
call   1050 <sock_ntop@plt>
test   %rax,%rax
je     11b8 <main+0x68>
lea    0xe97(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe57(%rip),%rdi
jmp    11bf <main+0x6f>
lea    0xe67(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11a9 <main+0x59>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [13 x i8] c"192.168.1.88\00"
@.str.1 = [25 x i8] c"inet_pton: AF_INET error\00"
@.str.2 = [16 x i8] c"sock_ntop error\00"
@.str.3 = [27 x i8] c"after sock_ntop: str = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %4, i32* %5
%6 = call i32 @htons(i32 12345)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%10 = call i64 @inet_pton(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = icmp sle i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %23
14: ; preds = %0
%15 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%16 = call i8* @sock_ntop(%struct.sockaddr* %15, i32 12)
store i8* %16, i8** %2
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %23
20: ; preds = %14
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %21)
store i32 0, i32* %1
br label %23
23: ; preds = %20, %18, %12
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [13 x i8] c"192.168.1.88\00"
@.str.1 = [25 x i8] c"inet_pton: AF_INET error\00"
@.str.2 = [16 x i8] c"sock_ntop error\00"
@.str.3 = [27 x i8] c"after sock_ntop: str = %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %3, i32* %4
%5 = tail call i32 @htons(i32 12345)
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%9 = call i64 @inet_pton(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %8)
%10 = icmp slt i64 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %21
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%15 = call i8* @sock_ntop(%struct.sockaddr* %14, i32 12)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %21
21: ; preds = %19, %17, %11
%22 = phi i32 [ 1, %11 ], [ 1, %17 ], [ 0, %19 ]
ret i32 %22
}