#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 */

/* Variables and functions */
int create_inet_stream_socket(char *, char *, int, int /*<<< orphan*/);
int destroy_inet_socket(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int write(int, char *, int);
int main(void) {
  int ret;
  int sfd;
  char *buf = "abcde";
  ret = sfd = create_inet_stream_socket("::1", "55555", 4, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = write(sfd, buf, 5);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = destroy_inet_socket(sfd);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe92(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <create_inet_stream_socket@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a5 <main+0x55>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d4 <main+0x84>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <destroy_inet_socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fa <main+0xaa>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeae(%rip),%rdi
lea    0xeab(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <create_inet_stream_socket@plt>
test   %eax,%eax
js     1197 <main+0x47>
mov    %eax,%ebx
lea    0xe88(%rip),%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1197 <main+0x47>
mov    %ebx,%edi
call   1040 <destroy_inet_socket@plt>
test   %eax,%eax
js     1197 <main+0x47>
xor    %eax,%eax
pop    %rbx
ret
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"abcde\00"
@.str.1 = [4 x i8] c"::1\00"
@.str.2 = [6 x i8] c"55555\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = call i32 @create_inet_stream_socket(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 0)
store i32 %5, i32* %3
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i32 0)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %3
%13 = load i8*, i8** %4
%14 = call i32 @write(i32 %12, i8* %13, i32 5)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @perror(i32 0)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = load i32, i32* %3
%22 = call i32 @destroy_inet_socket(i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i32 0)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"abcde\00"
@.str.1 = [4 x i8] c"::1\00"
@.str.2 = [6 x i8] c"55555\00"
define i32 @main() {
%1 = tail call i32 @create_inet_stream_socket(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i32 0)
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @perror(i32 0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = tail call i32 @destroy_inet_socket(i32 %1)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i32 0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12
ret i32 0
}