#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 */
typedef size_t ssize_t;
typedef int pid_t;
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
size_t readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int streq(char *, char *);
size_t strlen(char *);
int sys_getpid();
int main(void) {
  char buf1[64], buf2[64];
  pid_t pid;
  ssize_t rv;
  pid = sys_getpid();
  snprintf(buf1, sizeof(buf1), "%u", pid);
  rv = readlink("/proc/self", buf2, sizeof(buf2));
  assert(rv == strlen(buf1));
  buf2[rv] = '\0';
  assert(streq(buf1, buf2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <sys_getpid@plt>
mov    %eax,-0x94(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x94(%rbp),%ecx
mov    $0x40,%esi
lea    0xe6b(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x40,%edx
call   1040 <readlink@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0xa0(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <streq@plt>
mov    %eax,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1030 <sys_getpid@plt>
lea    0xe86(%rip),%rdx
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1060 <snprintf@plt>
lea    0xe6e(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <readlink@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1080 <assert@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <streq@plt>
mov    %eax,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [11 x i8] c"/proc/self\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 (...) @sys_getpid()
store i32 %6, i32* %4
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* %4
%9 = call i32 @snprintf(i8* %7, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%11 = call i64 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 64)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
%15 = icmp eq i64 %12, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %5
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%22 = call i32 @streq(i8* %20, i8* %21)
%23 = call i32 @assert(i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [11 x i8] c"/proc/self\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @sys_getpid()
%6 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i64 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 64)
%8 = call i64 @strlen(i8* %3)
%9 = icmp eq i64 %7, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %12
%13 = call i32 @streq(i8* %3, i8* %4)
%14 = call i32 @assert(i32 %13)
ret i32 0
}