#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;
scalar_t__ close(int);
int /*<<< orphan*/ printf(char *, char const *, char *, char const *);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int _socket(char const *progname, char const *title, int type) {
  int fd;
  printf("%s: Testing %s(%s)\n", progname, "socket", title);
  if ((fd = socket(AF_INET, type, 0)) < 0)
    return 2;
  if (close(fd) != 0)
    return 3;
  return 0;
}


x86 assembly (clang, -O0):
<_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xeae(%rip),%rdi
lea    0xebb(%rip),%rdx
call   1030 <printf@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1189 <_socket+0x59>
movl   $0x2,-0x4(%rbp)
jmp    11ae <_socket+0x7e>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     11a7 <_socket+0x77>
movl   $0x3,-0x4(%rbp)
jmp    11ae <_socket+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_socket>:
push   %rbx
mov    %edx,%ebx
mov    %rsi,%rcx
mov    %rdi,%rsi
lea    0xec0(%rip),%rdi
lea    0xecd(%rip),%rdx
call   1030 <printf@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <socket@plt>
test   %eax,%eax
js     1176 <_socket+0x46>
mov    %eax,%edi
call   1040 <close@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,2),%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s: Testing %s(%s)\0A\00"
@.str.1 = [7 x i8] c"socket\00"
@AF_INET = global i32 0
define i32 @_socket(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* %7
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 2, i32* %4
br label %23
17: ; preds = %3
%18 = load i32, i32* %8
%19 = call i64 @close(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 3, i32* %4
br label %23
22: ; preds = %17
store i32 0, i32* %4
br label %23
23: ; preds = %22, %21, %16
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s: Testing %s(%s)\0A\00"
@.str.1 = [7 x i8] c"socket\00"
@AF_INET = global i32 0
define i32 @_socket(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%5 = load i32, i32* @AF_INET
%6 = tail call i32 @socket(i32 %5, i32 %2, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = tail call i64 @close(i32 %6)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 0, i32 3
br label %12
12: ; preds = %8, %3
%13 = phi i32 [ 2, %3 ], [ %11, %8 ]
ret i32 %13
}