#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int ioctl(int, int, unsigned long *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int custom_pid_time(int procfd, pid_t pid) {
  int err;
  unsigned long data = pid;
  if ((err = ioctl(procfd, 0x2346, &data)) < 0) {
    fprintf(stderr, "ioctl: /proc/snapshot: pid: %d: %s\n", pid,
            strerror(errno));
    return 0;
  }
  return (int)data;
}


x86 assembly (clang, -O0):
<custom_pid_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2346,%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11a4 <custom_pid_time+0x74>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ab <custom_pid_time+0x7b>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<custom_pid_time>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
movslq %esi,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdx
mov    $0x2346,%esi
call   1030 <ioctl@plt>
test   %eax,%eax
js     1152 <custom_pid_time+0x22>
mov    (%rsp),%eax
jmp    117e <custom_pid_time+0x4e>
mov    0x2e87(%rip),%rax
mov    (%rax),%ebp
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe90(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"ioctl: /proc/snapshot: pid: %d: %s\0A\00"
@errno = global i32 0
define i32 @custom_pid_time(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
store i64 %9, i64* %7
%10 = load i32, i32* %4
%11 = call i32 @ioctl(i32 %10, i32 9030, i64* %7)
store i32 %11, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* %5
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
store i32 0, i32* %3
br label %22
19: ; preds = %2
%20 = load i64, i64* %7
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
br label %22
22: ; preds = %19, %13
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"ioctl: /proc/snapshot: pid: %d: %s\0A\00"
@errno = global i32 0
define i32 @custom_pid_time(i32 %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = sext i32 %1 to i64
store i64 %5, i64* %3
%6 = call i32 @ioctl(i32 %0, i32 9030, i64* %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %11)
br label %16
13: ; preds = %2
%14 = load i64, i64* %3
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %13, %8
%17 = phi i32 [ 0, %8 ], [ %15, %13 ]
ret i32 %17
}