#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*/ time_t;
struct hostent {
  int /*<<< orphan*/ h_name;
};
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int getpid();
int /*<<< orphan*/ index(char *, char);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, int, unsigned long, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *os_genid(void) {
  static int pid = 0;
  static time_t curtime;
  static char hostname[64 + 1];
  char *result;
  struct hostent *hp;
  if (pid == 0) {
    pid = getpid();
    time(&curtime);
    gethostname(hostname, sizeof(hostname));
    if (!index(hostname, '.')) {
      hp = gethostbyname(hostname);
      if (hp) {
        strcpy(hostname, hp->h_name);
      }
    }
  }
  result = malloc(25 + strlen(hostname));
  sprintf(result, "%d.%lu@%s", pid, (unsigned long)curtime++, hostname);
  return result;
}


x86 assembly (clang, -O0):
<os_genid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2ee1(%rip)
jne    1220 <os_genid+0x90>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,0x2ece(%rip)
lea    0x2ecb(%rip),%rdi
call   1080 <time@plt>
lea    0x2ecb(%rip),%rdi
mov    $0x41,%esi
call   10a0 <gethostname@plt>
lea    0x2eba(%rip),%rdi
mov    $0x2e,%esi
call   1060 <index@plt>
cmp    $0x0,%eax
jne    121b <os_genid+0x8b>
lea    0x2ea0(%rip),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1216 <os_genid+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0x2e7f(%rip),%rdi
call   1030 <strcpy@plt>
jmp    121b <os_genid+0x8b>
jmp    1220 <os_genid+0x90>
lea    0x2e69(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x19,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3a(%rip),%edx
mov    0x2e38(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e2d(%rip)
movslq %eax,%rcx
lea    0xd9f(%rip),%rsi
lea    0x2e28(%rip),%r8
call   10b0 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_genid>:
push   %r14
push   %rbx
push   %rax
cmpl   $0x0,0x2ee5(%rip)
jne    11fa <os_genid+0x6a>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x2ed6(%rip)
lea    0x2ed3(%rip),%rdi
call   1080 <time@plt>
lea    0x2ed3(%rip),%rbx
mov    %rbx,%rdi
mov    $0x41,%esi
call   10a0 <gethostname@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <index@plt>
test   %eax,%eax
jne    11fa <os_genid+0x6a>
lea    0x2eae(%rip),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     11fa <os_genid+0x6a>
mov    (%rax),%esi
lea    0x2e9b(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e8f(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x19(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x2e65(%rip),%edx
movslq 0x2e62(%rip),%rcx
lea    0x1(%rcx),%eax
mov    %eax,0x2e59(%rip)
lea    0xdce(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%r8
call   10b0 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@os_genid.pid = internal global i32 0
@os_genid.curtime = internal global i32 0
@os_genid.hostname = internal global [65 x i8] zeroinitializer
@.str = [10 x i8] c"%d.%lu@%s\00"
define i8* @os_genid() {
%1 = alloca i8*
%2 = alloca %struct.hostent*
%3 = load i32, i32* @os_genid.pid
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %0
%6 = call i32 (...) @getpid()
store i32 %6, i32* @os_genid.pid
%7 = call i32 @time(i32* @os_genid.curtime)
%8 = call i32 @gethostname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i32 65)
%9 = call i32 @index(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i8 signext 46)
%10 = icmp ne i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %5
%12 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
store %struct.hostent* %12, %struct.hostent** %2
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = icmp ne %struct.hostent* %13, null
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load %struct.hostent*, %struct.hostent** %2
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @strcpy(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %15, %11
br label %21
21: ; preds = %20, %5
br label %22
22: ; preds = %21, %0
%23 = call i64 @strlen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
%24 = add nsw i64 25, %23
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %1
%26 = load i8*, i8** %1
%27 = load i32, i32* @os_genid.pid
%28 = load i32, i32* @os_genid.curtime
%29 = add nsw i32 %28, 1
store i32 %29, i32* @os_genid.curtime
%30 = sext i32 %28 to i64
%31 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %27, i64 %30, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
%32 = load i8*, i8** %1
ret i8* %32
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@os_genid.pid = internal unnamed_addr global i32 0
@os_genid.curtime = internal global i32 0
@os_genid.hostname = internal global [65 x i8] zeroinitializer
@.str = [10 x i8] c"%d.%lu@%s\00"
define noalias i8* @os_genid() {
%1 = load i32, i32* @os_genid.pid
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %16
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
store i32 %4, i32* @os_genid.pid
%5 = tail call i32 @time(i32* @os_genid.curtime)
%6 = tail call i32 @gethostname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i32 65)
%7 = tail call i32 @index(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i8 signext 46)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @strcpy(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %3, %12, %9, %0
%17 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
%18 = add nsw i64 %17, 25
%19 = tail call i8* @malloc(i64 %18)
%20 = load i32, i32* @os_genid.pid
%21 = load i32, i32* @os_genid.curtime
%22 = add nsw i32 %21, 1
store i32 %22, i32* @os_genid.curtime
%23 = sext i32 %21 to i64
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20, i64 %23, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @os_genid.hostname, i64 0, i64 0))
ret i8* %19
}