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

/* Variables and functions */
int /*<<< orphan*/ finish();
int /*<<< orphan*/ makedir(char *);
int /*<<< orphan*/ outs(char const *);
int /*<<< orphan*/ owner(int, int);
int /*<<< orphan*/ perm(int);
int /*<<< orphan*/ start(char *);
void makelog(const char *user, int uid, int gid) {
  makedir("log");
  perm(02755);
  makedir("log/main");
  owner(uid, gid);
  perm(02755);
  start("log/status");
  finish();
  owner(uid, gid);
  perm(0644);
  start("log/run");
  outs("#!/bin/sh\nexec");
  outs(" chpst -u ");
  outs(user);
  outs(" svlogd -tt ./main\n");
  finish();
  perm(0755);
}


x86 assembly (clang, -O0):
<makelog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe87(%rip),%rdi
call   1060 <makedir@plt>
mov    $0x5ed,%edi
call   1070 <perm@plt>
lea    0xe75(%rip),%rdi
call   1060 <makedir@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <owner@plt>
mov    $0x5ed,%edi
call   1070 <perm@plt>
lea    0xe5d(%rip),%rdi
call   1050 <start@plt>
mov    $0x0,%al
call   1030 <finish@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <owner@plt>
mov    $0x1a4,%edi
call   1070 <perm@plt>
lea    0xe40(%rip),%rdi
call   1050 <start@plt>
lea    0xe3c(%rip),%rdi
call   1080 <outs@plt>
lea    0xe3f(%rip),%rdi
call   1080 <outs@plt>
mov    -0x8(%rbp),%rdi
call   1080 <outs@plt>
lea    0xe35(%rip),%rdi
call   1080 <outs@plt>
mov    $0x0,%al
call   1030 <finish@plt>
mov    $0x1ed,%edi
call   1070 <perm@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makelog>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xe8e(%rip),%rdi
call   1060 <makedir@plt>
mov    $0x5ed,%edi
call   1070 <perm@plt>
lea    0xe7c(%rip),%rdi
call   1060 <makedir@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <owner@plt>
mov    $0x5ed,%edi
call   1070 <perm@plt>
lea    0xe66(%rip),%rdi
call   1050 <start@plt>
xor    %eax,%eax
call   1030 <finish@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <owner@plt>
mov    $0x1a4,%edi
call   1070 <perm@plt>
lea    0xe4b(%rip),%rdi
call   1050 <start@plt>
lea    0xe47(%rip),%rdi
call   1080 <outs@plt>
lea    0xe4a(%rip),%rdi
call   1080 <outs@plt>
mov    %r14,%rdi
call   1080 <outs@plt>
lea    0xe41(%rip),%rdi
call   1080 <outs@plt>
xor    %eax,%eax
call   1030 <finish@plt>
mov    $0x1ed,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <perm@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"log\00"
@.str.1 = [9 x i8] c"log/main\00"
@.str.2 = [11 x i8] c"log/status\00"
@.str.3 = [8 x i8] c"log/run\00"
@.str.4 = [15 x i8] c"#!/bin/sh\0Aexec\00"
@.str.5 = [11 x i8] c" chpst -u \00"
@.str.6 = [20 x i8] c" svlogd -tt ./main\0A\00"
define void @makelog(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = call i32 @makedir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @perm(i32 1517)
%9 = call i32 @makedir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @owner(i32 %10, i32 %11)
%13 = call i32 @perm(i32 1517)
%14 = call i32 @start(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @finish()
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @owner(i32 %16, i32 %17)
%19 = call i32 @perm(i32 420)
%20 = call i32 @start(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @outs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @outs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%23 = load i8*, i8** %4
%24 = call i32 @outs(i8* %23)
%25 = call i32 @outs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 (...) @finish()
%27 = call i32 @perm(i32 493)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"log\00"
@.str.1 = [9 x i8] c"log/main\00"
@.str.2 = [11 x i8] c"log/status\00"
@.str.3 = [8 x i8] c"log/run\00"
@.str.4 = [15 x i8] c"#!/bin/sh\0Aexec\00"
@.str.5 = [11 x i8] c" chpst -u \00"
@.str.6 = [20 x i8] c" svlogd -tt ./main\0A\00"
define void @makelog(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @makedir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @perm(i32 1517)
%6 = tail call i32 @makedir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @owner(i32 %1, i32 %2)
%8 = tail call i32 @perm(i32 1517)
%9 = tail call i32 @start(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 (...) @finish()
%11 = tail call i32 @owner(i32 %1, i32 %2)
%12 = tail call i32 @perm(i32 420)
%13 = tail call i32 @start(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @outs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @outs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @outs(i8* %0)
%17 = tail call i32 @outs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%18 = tail call i32 (...) @finish()
%19 = tail call i32 @perm(i32 493)
ret void
}