#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ open(char const *const, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int strlen(char *);
size_t write(int, char *, size_t);
void write_ugidmap(const char *const path, int ugid) {
  int fd = check(open(path, O_WRONLY), "open(ugidmap)");
  char buf[1024] = "";
  snprintf(buf, sizeof(buf), "%d %d 1", ugid, ugid);
  size_t len = strlen(buf) + 1;
  if (write(fd, buf, len) != len) {
    err(1, "write(ugidmap)");
  }
  check(close(fd), "close(ugidmap)");
}


x86 assembly (clang, -O0):
<write_ugidmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%edi
lea    0xe53(%rip),%rsi
call   10a0 <check@plt>
mov    %eax,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0x400,%esi
lea    0xe2c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x418(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x418(%rbp),%rax
je     1233 <write_ugidmap+0xb3>
mov    $0x1,%edi
lea    0xde8(%rip),%rsi
call   1080 <err@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    %eax,%edi
lea    0xde1(%rip),%rsi
call   10a0 <check@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ugidmap>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ebp
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
lea    0xe5e(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
mov    %eax,%r14d
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe49(%rip),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
cmp    %rbp,%rax
je     1209 <write_ugidmap+0x89>
lea    0xe17(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %r14d,%edi
call   1070 <close@plt>
lea    0xe0d(%rip),%rsi
mov    %eax,%edi
call   10a0 <check@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [14 x i8] c"open(ugidmap)\00"
@.str.1 = [8 x i8] c"%d %d 1\00"
@.str.2 = [15 x i8] c"write(ugidmap)\00"
@.str.3 = [15 x i8] c"close(ugidmap)\00"
define void @write_ugidmap(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %8, i32 %9)
%11 = call i32 @check(i32 %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %5
%12 = bitcast [1024 x i8]* %6 to i8*
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
store i64 %20, i64* %7
%21 = load i32, i32* %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i64, i64* %7
%24 = call i64 @write(i32 %21, i8* %22, i64 %23)
%25 = load i64, i64* %7
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %2
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
%32 = call i32 @check(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [14 x i8] c"open(ugidmap)\00"
@.str.1 = [8 x i8] c"%d %d 1\00"
@.str.2 = [15 x i8] c"write(ugidmap)\00"
@.str.3 = [15 x i8] c"close(ugidmap)\00"
define void @write_ugidmap(i8* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = tail call i32 @check(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %1)
%9 = call i32 @strlen(i8* %7)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = call i64 @write(i32 %6, i8* %7, i64 %11)
%13 = icmp eq i64 %12, %11
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = call i32 @close(i32 %6)
%18 = call i32 @check(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
ret void
}