#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 sync_merge_data {
  int fd2;
  char *name;
  int fence;
};

/* Variables and functions */
int /*<<< orphan*/ SYNC_IOC_MERGE;
int ioctl(int, int /*<<< orphan*/, struct sync_merge_data *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int sync_merge(const char *name, int fd1, int fd2) {
  struct sync_merge_data data = {};
  int err;
  data.fd2 = fd2;
  strncpy(data.name, name, sizeof(data.name) - 1);
  data.name[sizeof(data.name) - 1] = '\0';
  err = ioctl(fd1, SYNC_IOC_MERGE, &data);
  if (err < 0)
    return err;
  return data.fence;
}


x86 assembly (clang, -O0):
<sync_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x14(%rbp),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    119f <sync_merge+0x6f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <sync_merge+0x75>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_merge>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %edx,(%rsp)
xor    %edi,%edi
mov    $0x7,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
js     116c <sync_merge+0x4c>
mov    0x10(%rsp),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sync_merge_data = type { i32, i8*, i32 }
@SYNC_IOC_MERGE = global i32 0
define i32 @sync_merge(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sync_merge_data
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = bitcast %struct.sync_merge_data* %8 to i8*
%11 = load i32, i32* %7
%12 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %8, i32 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %8, i32 0, i32 1
%14 = load i8*, i8** %13
%15 = load i8*, i8** %5
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 7)
%17 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %8, i32 0, i32 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 7
store i8 0, i8* %19
%20 = load i32, i32* %6
%21 = load i32, i32* @SYNC_IOC_MERGE
%22 = call i32 @ioctl(i32 %20, i32 %21, %struct.sync_merge_data* %8)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = load i32, i32* %9
store i32 %26, i32* %4
br label %30
27: ; preds = %3
%28 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %8, i32 0, i32 2
%29 = load i32, i32* %28
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %25
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.sync_merge_data = type { i32, i8*, i32 }
@SYNC_IOC_MERGE = global i32 0
define i32 @sync_merge(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sync_merge_data
%5 = bitcast %struct.sync_merge_data* %4 to i8*
%6 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %4, i64 0, i32 0
store i32 %2, i32* %6
%7 = tail call i32 @strncpy(i8* null, i8* %0, i32 7)
store i8 0, i8* inttoptr (i64 7 to i8*)
%8 = load i32, i32* @SYNC_IOC_MERGE
%9 = call i32 @ioctl(i32 %1, i32 %8, %struct.sync_merge_data* %4)
%10 = icmp slt i32 %9, 0
%11 = getelementptr inbounds %struct.sync_merge_data, %struct.sync_merge_data* %4, i64 0, i32 2
%12 = load i32, i32* %11
%13 = select i1 %10, i32 %9, i32 %12
ret i32 %13
}