#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 stat {
  unsigned long st_mode;
  int /*<<< orphan*/ st_mtime;
};
typedef int /*<<< orphan*/ dev_t;

/* Variables and functions */
unsigned long S_IFMT;
int /*<<< orphan*/ chown(char *, unsigned long, unsigned long);
int /*<<< orphan*/ error_msg_and_die(char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mknod(char *, unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void add_new_device(char *name, char *path, unsigned long uid,
                    unsigned long gid, unsigned long mode, dev_t rdev) {
  int status;
  struct stat sb;
  time_t timestamp = time(NULL);
  memset(&sb, 0, sizeof(struct stat));
  status = lstat(path, &sb);
  if (status >= 0) {
    if ((mode & S_IFMT) != (sb.st_mode & S_IFMT))
      error_msg_and_die("%s: file type does not match specified type!", path);
    timestamp = sb.st_mtime;
  }
  mknod(name, mode, rdev);
  chown(path, uid, gid);
}


x86 assembly (clang, -O0):
<add_new_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     11f1 <add_new_device+0x91>
mov    -0x28(%rbp),%rax
mov    0x2e1f(%rip),%rcx
and    (%rcx),%rax
mov    -0x40(%rbp),%rcx
mov    0x2e11(%rip),%rdx
and    (%rdx),%rcx
cmp    %rcx,%rax
je     11eb <add_new_device+0x8b>
mov    -0x10(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1050 <error_msg_and_die@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <mknod@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <chown@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_new_device>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8,%rbp
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
xor    %edi,%edi
call   1070 <time@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <lstat@plt>
test   %eax,%eax
js     11ce <add_new_device+0x6e>
mov    0x2e2e(%rip),%rax
mov    0x8(%rsp),%rcx
xor    %rbp,%rcx
test   %rcx,(%rax)
je     11ce <add_new_device+0x6e>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <error_msg_and_die@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1060 <mknod@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    (%rsp),%rdx
call   1080 <chown@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@S_IFMT = global i64 0
@.str = [45 x i8] c"%s: file type does not match specified type!\00"
define void @add_new_device(i8* %0, i8* %1, i64 %2, i64 %3, i64 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.stat
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i32 %5, i32* %12
%16 = call i32 @time(i32* null)
store i32 %16, i32* %15
%17 = call i32 @memset(%struct.stat* %14, i32 0, i32 16)
%18 = load i8*, i8** %8
%19 = call i32 @lstat(i8* %18, %struct.stat* %14)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %6
%23 = load i64, i64* %11
%24 = load i64, i64* @S_IFMT
%25 = and i64 %23, %24
%26 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @S_IFMT
%29 = and i64 %27, %28
%30 = icmp ne i64 %25, %29
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i8*, i8** %8
%33 = call i32 @error_msg_and_die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %22
%35 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 1
%36 = load i32, i32* %35
store i32 %36, i32* %15
br label %37
37: ; preds = %34, %6
%38 = load i8*, i8** %7
%39 = load i64, i64* %11
%40 = load i32, i32* %12
%41 = call i32 @mknod(i8* %38, i64 %39, i32 %40)
%42 = load i8*, i8** %8
%43 = load i64, i64* %9
%44 = load i64, i64* %10
%45 = call i32 @chown(i8* %42, i64 %43, i64 %44)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@S_IFMT = global i64 0
@.str = [45 x i8] c"%s: file type does not match specified type!\00"
define void @add_new_device(i8* %0, i8* %1, i64 %2, i64 %3, i64 %4, i32 %5) {
%7 = alloca %struct.stat
%8 = bitcast %struct.stat* %7 to i8*
%9 = tail call i32 @time(i32* null)
%10 = call i32 @memset(%struct.stat* %7, i32 0, i32 16)
%11 = call i32 @lstat(i8* %1, %struct.stat* %7)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %22
13: ; preds = %6
%14 = load i64, i64* @S_IFMT
%15 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%16 = load i64, i64* %15
%17 = xor i64 %16, %4
%18 = and i64 %17, %14
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = call i32 @error_msg_and_die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %22
22: ; preds = %13, %20, %6
%23 = call i32 @mknod(i8* %0, i64 %4, i32 %5)
%24 = call i32 @chown(i8* %1, i64 %2, i64 %3)
ret void
}