#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 int /*<<< orphan*/ pidstr;
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ getpid();
int /*<<< orphan*/ snprintf(char *, int, char *, scalar_t__);
const char *get_pidstr(int reset) {
  static char pidstr[24];
  static pid_t pid = 0;
  if (1 == reset || (0 == pid)) {
    pid = getpid();
    (void)snprintf(pidstr, sizeof(pidstr), "%d", pid);
  }
  return pidstr;
}


x86 assembly (clang, -O0):
<get_pidstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1,%eax
cmp    -0x4(%rbp),%eax
je     1148 <get_pidstr+0x28>
xor    %eax,%eax
cmp    0x2f16(%rip),%rax
jne    1175 <get_pidstr+0x55>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,0x2f02(%rip)
mov    0x2efb(%rip),%rcx
lea    0x2edc(%rip),%rdi
mov    $0x18,%esi
lea    0xe90(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ec4(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pidstr>:
push   %rax
cmp    $0x1,%edi
je     1130 <get_pidstr+0x10>
cmpq   $0x0,0x2f2a(%rip)
jne    1159 <get_pidstr+0x39>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,0x2f1a(%rip)
lea    0x2efb(%rip),%rdi
lea    0xeb4(%rip),%rdx
mov    $0x18,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
lea    0x2ee0(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@get_pidstr.pidstr = internal global [24 x i8] zeroinitializer
@get_pidstr.pid = internal global i64 0
@.str = [3 x i8] c"%d\00"
define i8* @get_pidstr(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 1, %3
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i64, i64* @get_pidstr.pid
%7 = icmp eq i64 0, %6
br i1 %7, label %8, label %12
8: ; preds = %5, %1
%9 = call i64 (...) @getpid()
store i64 %9, i64* @get_pidstr.pid
%10 = load i64, i64* @get_pidstr.pid
%11 = call i32 @snprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @get_pidstr.pidstr, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %12
12: ; preds = %8, %5
ret i8* getelementptr inbounds ([24 x i8], [24 x i8]* @get_pidstr.pidstr, i64 0, i64 0)
}

LLVM IR (-O2):
@get_pidstr.pidstr = internal global [24 x i8] zeroinitializer
@get_pidstr.pid = internal unnamed_addr global i64 0
@.str = [3 x i8] c"%d\00"
define i8* @get_pidstr(i32 %0) {
%2 = icmp eq i32 %0, 1
%3 = load i64, i64* @get_pidstr.pid
%4 = icmp eq i64 %3, 0
%5 = select i1 %2, i1 true, i1 %4
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i64 (...) @getpid()
store i64 %7, i64* @get_pidstr.pid
%8 = tail call i32 @snprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @get_pidstr.pidstr, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %9
9: ; preds = %1, %6
ret i8* getelementptr inbounds ([24 x i8], [24 x i8]* @get_pidstr.pidstr, i64 0, i64 0)
}