#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 stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, int, int, int);
scalar_t__ fstat(int, struct stat *);
int socket(int, int, int);
void dotest(int domain, int type, int protocol) {
  struct stat sb;
  int sock;
  sock = socket(domain, type, protocol);
  if (sock < 0)
    err(-1, "socket(%d, %d, %d)", domain, type, protocol);
  if (fstat(sock, &sb) < 0)
    err(-1, "fstat on socket(%d, %d, %d)", domain, type, protocol);
  close(sock);
}


x86 assembly (clang, -O0):
<dotest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1187 <dotest+0x47>
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0xffffffff,%edi
lea    0xe87(%rip),%rsi
call   1040 <err@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
jge    11b8 <dotest+0x78>
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0xffffffff,%edi
lea    0xe4d(%rip),%rsi
call   1040 <err@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
call   1060 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1173 <dotest+0x33>
lea    0xea8(%rip),%rsi
mov    $0xffffffff,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1040 <err@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1050 <fstat@plt>
test   %rax,%rax
jns    119b <dotest+0x5b>
lea    0xe77(%rip),%rsi
mov    $0xffffffff,%edi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1040 <err@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <close@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [19 x i8] c"socket(%d, %d, %d)\00"
@.str.1 = [28 x i8] c"fstat on socket(%d, %d, %d)\00"
define void @dotest(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @err(i32 -1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
br label %20
20: ; preds = %15, %3
%21 = load i32, i32* %8
%22 = call i64 @fstat(i32 %21, %struct.stat* %7)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 @err(i32 -1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
br label %29
29: ; preds = %24, %20
%30 = load i32, i32* %8
%31 = call i32 @close(i32 %30)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [19 x i8] c"socket(%d, %d, %d)\00"
@.str.1 = [28 x i8] c"fstat on socket(%d, %d, %d)\00"
define void @dotest(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @err(i32 -1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
br label %10
10: ; preds = %8, %3
%11 = call i64 @fstat(i32 %6, %struct.stat* %4)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @err(i32 -1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @close(i32 %6)
ret void
}