#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 /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int sock1, sock2;
  if ((sock1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  close(sock1);
  if ((sock2 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return (EXIT_FAILURE);
  close(sock2);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    116c <main+0x4c>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <main+0xa5>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11b1 <main+0x91>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <main+0xa5>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb9(%rip),%r14
mov    (%r14),%edi
mov    0x2e97(%rip),%r15
mov    (%r15),%esi
mov    0x2e9d(%rip),%r12
mov    (%r12),%edx
call   1040 <socket@plt>
mov    0x2e75(%rip),%rbx
test   %eax,%eax
js     117f <main+0x5f>
mov    %eax,%edi
call   1030 <close@plt>
mov    (%r14),%edi
mov    (%r15),%esi
mov    (%r12),%edx
call   1040 <socket@plt>
test   %eax,%eax
js     117f <main+0x5f>
mov    %eax,%edi
call   1030 <close@plt>
mov    0x2e41(%rip),%rbx
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = load i32, i32* @IPPROTO_TCP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* @EXIT_FAILURE
store i32 %10, i32* %1
br label %25
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = load i32, i32* @IPPROTO_TCP
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %1
br label %25
21: ; preds = %11
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %1
br label %25
25: ; preds = %21, %19, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_STREAM
%3 = load i32, i32* @IPPROTO_TCP
%4 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = tail call i32 @close(i32 %4)
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = tail call i32 @close(i32 %11)
br label %15
15: ; preds = %6, %0, %13
%16 = phi i32* [ @EXIT_SUCCESS, %13 ], [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %6 ]
%17 = load i32, i32* %16
ret i32 %17
}