#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strtok_r(char *, char *, char **);
const char *log_ident() {
  FILE *self;
  static char line[64];
  char *p = NULL;
  char *sbuf;
  if ((self = fopen("/proc/self/status", "r")) != NULL) {
    while (fgets(line, sizeof(line), self)) {
      if (!strncmp(line, "Name:", 5)) {
        strtok_r(line, "\t\n", &sbuf);
        p = strtok_r(NULL, "\t\n", &sbuf);
        break;
      }
    }
    fclose(self);
  }
  return p;
}


x86 assembly (clang, -O0):
<log_ident>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xe99(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1208 <log_ident+0xb8>
jmp    1186 <log_ident+0x36>
mov    -0x8(%rbp),%rdx
lea    0x2ecf(%rip),%rdi
mov    $0x40,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11ff <log_ident+0xaf>
lea    0x2eb4(%rip),%rdi
lea    0xe61(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11fa <log_ident+0xaa>
lea    0x2e93(%rip),%rdi
lea    0xe46(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <strtok_r@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe32(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x10(%rbp)
jmp    11ff <log_ident+0xaf>
jmp    1186 <log_ident+0x36>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_ident>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ef <log_ident+0x9f>
mov    %rax,%r15
lea    0x2ee6(%rip),%rbx
xor    %r14d,%r14d
lea    0xe90(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e5 <log_ident+0x95>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <log_ident+0x40>
lea    0x2ea0(%rip),%rdi
lea    0xe53(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    11f2 <log_ident+0xa2>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@log_ident.line = internal global [64 x i8] zeroinitializer
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Name:\00"
@.str.3 = [3 x i8] c"\09\0A\00"
define i8* @log_ident() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
store i8* null, i8** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %21
6: ; preds = %0
br label %7
7: ; preds = %17, %6
%8 = load i32*, i32** %1
%9 = call i64 @fgets(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i32 64, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = call i32 @strncmp(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i8* @strtok_r(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %3)
%16 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %3)
store i8* %16, i8** %2
br label %18
17: ; preds = %11
br label %7
18: ; preds = %14, %7
%19 = load i32*, i32** %1
%20 = call i32 @fclose(i32* %19)
br label %21
21: ; preds = %18, %0
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@log_ident.line = internal global [64 x i8] zeroinitializer
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Name:\00"
@.str.3 = [3 x i8] c"\09\0A\00"
define i8* @log_ident() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %0, %8
%6 = tail call i64 @fgets(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i32 64, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i32 @strncmp(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8
%12 = call i8* @strtok_r(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @log_ident.line, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %1)
%13 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %1)
br label %14
14: ; preds = %5, %11
%15 = phi i8* [ %13, %11 ], [ null, %5 ]
%16 = call i32 @fclose(i32* %3)
br label %17
17: ; preds = %14, %0
%18 = phi i8* [ %15, %14 ], [ null, %0 ]
ret i8* %18
}