#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 {
  long st_nlink;
};

/* Variables and functions */
long countlength(long);
int /*<<< orphan*/ myitoa(long, char *);
int mystrlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void getnumoflinks(struct stat fileStat) {
  long numoflinks = fileStat.st_nlink;
  long sizeof_numoflinks = countlength(numoflinks);
  char count[sizeof_numoflinks + 1];
  myitoa(numoflinks, count);
  write(1, count, mystrlen(count));
  int p;
  for (p = 0; p < 2 - (mystrlen(count)); ++p)
    write(1, " ", 1);
}


x86 assembly (clang, -O0):
<getnumoflinks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <countlength@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <myitoa@plt>
mov    -0x38(%rbp),%rdi
call   1040 <mystrlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
call   1040 <mystrlen@plt>
mov    %eax,%edx
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11f9 <getnumoflinks+0xb9>
mov    $0x1,%edx
lea    0xe1c(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b5 <getnumoflinks+0x75>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnumoflinks>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <countlength@plt>
mov    %rsp,%r15
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <myitoa@plt>
mov    %r15,%rdi
call   1040 <mystrlen@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15,%rdi
call   1040 <mystrlen@plt>
cmp    $0x1,%eax
jg     11c8 <getnumoflinks+0x88>
xor    %ebx,%ebx
lea    0xe65(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1040 <mystrlen@plt>
mov    $0x2,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebx
jl     11a0 <getnumoflinks+0x60>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @getnumoflinks(i64 %0) {
%2 = tail call i64 @countlength(i64 %0)
%3 = add nsw i64 %2, 1
%4 = alloca i8, i64 %3
%5 = call i32 @myitoa(i64 %0, i8* %4)
%6 = call i32 @mystrlen(i8* %4)
%7 = call i32 @write(i32 1, i8* %4, i32 %6)
%8 = call i32 @mystrlen(i8* %4)
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %1, %10
%11 = phi i32 [ %13, %10 ], [ 0, %1 ]
%12 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = add nuw nsw i32 %11, 1
%14 = call i32 @mystrlen(i8* %4)
%15 = sub nsw i32 2, %14
%16 = icmp slt i32 %13, %15
br i1 %16, label %10, label %17
17: ; preds = %10, %1
ret void
}