#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 stat {
  int /*<<< orphan*/ st_dev;
};
typedef int /*<<< orphan*/ fsid_t;

/* Variables and functions */
int /*<<< orphan*/ fillfsid(int /*<<< orphan*/, int /*<<< orphan*/ *);
int find_union(char *, char **, char **, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
int mkfsid(char *path, fsid_t *fsid) {
  int err = 0;
  char *actual_path = NULL;
  char *options = NULL;
  struct stat stat_struct;
  memset(&stat_struct, 0, sizeof(struct stat));
  err = find_union(path, &options, &actual_path, 0);
  if (err) {
    printf("find_union failed:\n");
    goto out;
  }
  err = stat(actual_path, &stat_struct);
  if (err) {
    perror("Couldent stat path: ");
    goto out;
  }
  fillfsid(stat_struct.st_dev, fsid);
out:
  return err;
}


x86 assembly (clang, -O0):
<mkfsid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <find_union@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c8 <mkfsid+0x68>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <mkfsid+0x9f>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f3 <mkfsid+0x93>
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
jmp    11ff <mkfsid+0x9f>
mov    -0x30(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <fillfsid@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkfsid>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
xor    %ecx,%ecx
call   1040 <find_union@plt>
test   %eax,%eax
je     11b5 <mkfsid+0x55>
mov    %eax,%ebp
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
jmp    11d3 <mkfsid+0x73>
mov    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1070 <stat@plt>
test   %eax,%eax
jne    11dc <mkfsid+0x7c>
mov    (%rsp),%edi
mov    %rbx,%rsi
call   1060 <fillfsid@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe1b(%rip),%rdi
call   1080 <perror@plt>
jmp    11d3 <mkfsid+0x73>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"find_union failed:\0A\00"
@.str.1 = [21 x i8] c"Couldent stat path: \00"
define i32 @mkfsid(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i8* null, i8** %6
store i8* null, i8** %7
%9 = call i32 @memset(%struct.stat* %8, i32 0, i32 4)
%10 = load i8*, i8** %3
%11 = call i32 @find_union(i8* %10, i8** %7, i8** %6, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %28
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32 @stat(i8* %17, %struct.stat* %8)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %28
23: ; preds = %16
%24 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32*, i32** %4
%27 = call i32 @fillfsid(i32 %25, i32* %26)
br label %28
28: ; preds = %23, %21, %14
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [21 x i8] c"Couldent stat path: \00"
@str = [19 x i8] c"find_union failed:\00"
define i32 @mkfsid(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = bitcast %struct.stat* %5 to i8*
%9 = call i32 @memset(%struct.stat* %5, i32 0, i32 4)
%10 = call i32 @find_union(i8* %0, i8** %4, i8** %3, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %24
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @stat(i8* %15, %struct.stat* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @fillfsid(i32 %22, i32* %1)
br label %24
24: ; preds = %20, %18, %12
%25 = phi i32 [ %10, %12 ], [ %16, %18 ], [ 0, %20 ]
ret i32 %25
}