#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 /*<<< orphan*/ SOCK_STREAM;
unsigned long long atoll(char *);
int /*<<< orphan*/ close(int const);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: perf <loopcnt>\n");
    return 1;
  }
  unsigned long long const loopcnt = atoll(argv[1]);
  unsigned long long i;
  for (i = 0; i < loopcnt; ++i) {
    int const fd = socket(AF_INET, SOCK_STREAM, 0);
    if (fd == -1) {
      perror("socket");
      return 1;
    }
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoll@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1206 <main+0xb6>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11ed <main+0x9d>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <main+0xbd>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a1 <main+0x51>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11a3 <main+0x53>
mov    0x8(%rsi),%rdi
call   1050 <atoll@plt>
test   %rax,%rax
je     119f <main+0x4f>
mov    %rax,%rbx
mov    0x2e76(%rip),%r14
mov    0x2e5f(%rip),%r15
nopl   0x0(%rax)
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     11ba <main+0x6a>
mov    %eax,%edi
call   1040 <close@plt>
add    $0xffffffffffffffff,%rbx
jne    1180 <main+0x30>
xor    %eax,%eax
jmp    11b4 <main+0x64>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
jmp    11af <main+0x5f>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: perf <loopcnt>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %37
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @atoll(i8* %16)
store i64 %17, i64* %6
store i64 0, i64* %7
br label %18
18: ; preds = %33, %13
%19 = load i64, i64* %7
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %37
30: ; preds = %22
%31 = load i32, i32* %8
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30
%34 = load i64, i64* %7
%35 = add i64 %34, 1
store i64 %35, i64* %7
br label %18
36: ; preds = %18
store i32 0, i32* %3
br label %37
37: ; preds = %36, %28, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@str = [22 x i8] c"Usage: perf <loopcnt>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %23
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @atoll(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %6, %19
%12 = phi i64 [ %21, %19 ], [ 0, %6 ]
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
19: ; preds = %11
%20 = tail call i32 @close(i32 %15)
%21 = add nuw i64 %12, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %23, label %11
23: ; preds = %19, %6, %17, %4
%24 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %6 ], [ 0, %19 ]
ret i32 %24
}