#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 */
struct timespec {
  int member_0;
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
  int /*<<< orphan*/ member_1;
};
typedef enum nss_status { ____Placeholder_nss_status } nss_status;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_NOTICE;
int NSS_STATUS_NOTFOUND;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, ...);
enum nss_status inject(char *name) {
  int enabled = 0;
  struct timespec delay = {30, 0};
  char buffer[80];
  FILE *sentinal;
  sprintf(buffer, "/tmp/inject.%s", name);
  sentinal = fopen(buffer, "r");
  if (sentinal != NULL) {
    int assigned = fscanf(sentinal, "%ld.%09ld", &delay.tv_sec, &delay.tv_nsec);
    fclose(sentinal);
    if (assigned != 2)
      return NSS_STATUS_NOTFOUND;
    enabled = 1;
  }
  if (enabled) {
    syslog(LOG_NOTICE, "{%s} inject delay %ld.%09ld", name, delay.tv_sec,
           delay.tv_nsec);
    nanosleep(&delay, 0);
    syslog(LOG_NOTICE, "{%s} inject delay complete", name);
  }
  return NSS_STATUS_NOTFOUND;
}


x86 assembly (clang, -O0):
<inject>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     121f <inject+0xbf>
mov    -0x88(%rbp),%rdi
lea    -0x28(%rbp),%rdx
add    $0x8,%rdx
lea    -0x28(%rbp),%rcx
add    $0x4,%rcx
lea    0xe50(%rip),%rsi
call   1050 <fscanf@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x2,-0x8c(%rbp)
je     1218 <inject+0xb8>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127d <inject+0x11d>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1271 <inject+0x111>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inject>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%r14
movups 0xe8e(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe93(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     120c <inject+0xac>
mov    %rax,%rbx
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x2,%ebp
jne    120c <inject+0xac>
mov    0x2e0d(%rip),%rbx
mov    (%rbx),%edi
mov    0x4(%rsp),%r8d
mov    0x8(%rsp),%ecx
lea    0xe3c(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    (%rbx),%edi
lea    0xe3b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32, i32, i32 }
@__const.inject.delay = %struct.timespec { i32 30, i32 0, i32 0, i32 0 }
@.str = [15 x i8] c"/tmp/inject.%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"%ld.%09ld\00"
@NSS_STATUS_NOTFOUND = global i32 0
@LOG_NOTICE = global i32 0
@.str.3 = [28 x i8] c"{%s} inject delay %ld.%09ld\00"
@.str.4 = [27 x i8] c"{%s} inject delay complete\00"
define i32 @inject(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = alloca [80 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%9 = bitcast %struct.timespec* %5 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %29
17: ; preds = %1
%18 = load i32*, i32** %7
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 2
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%21 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %19, i32* %20)
store i32 %21, i32* %8
%22 = load i32*, i32** %7
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 2
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %27, i32* %2
br label %46
28: ; preds = %17
store i32 1, i32* %4
br label %29
29: ; preds = %28, %1
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i32, i32* @LOG_NOTICE
%34 = load i8*, i8** %3
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 2
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32 %36, i32 %38)
%40 = call i32 @nanosleep(%struct.timespec* %5, i32 0)
%41 = load i32, i32* @LOG_NOTICE
%42 = load i8*, i8** %3
%43 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %32, %29
%45 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %45, i32* %2
br label %46
46: ; preds = %44, %26
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32, i32, i32 }
@__const.inject.delay = %struct.timespec { i32 30, i32 0, i32 0, i32 0 }
@.str = [15 x i8] c"/tmp/inject.%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"%ld.%09ld\00"
@NSS_STATUS_NOTFOUND = global i32 0
@LOG_NOTICE = global i32 0
@.str.3 = [28 x i8] c"{%s} inject delay %ld.%09ld\00"
@.str.4 = [27 x i8] c"{%s} inject delay complete\00"
define i32 @inject(i8* %0) {
%2 = alloca %struct.timespec
%3 = alloca [80 x i8]
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 2
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%12 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %11)
%13 = call i32 @fclose(i32* %7)
%14 = icmp eq i32 %12, 2
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load i32, i32* @LOG_NOTICE
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %17, i32 %18)
%20 = call i32 @nanosleep(%struct.timespec* %2, i32 0)
%21 = load i32, i32* @LOG_NOTICE
%22 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %23
23: ; preds = %15, %1, %9
%24 = load i32, i32* @NSS_STATUS_NOTFOUND
ret i32 %24
}