#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 */
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ symlink(char *, char *);
int create_usr_links(void) {
  if (mkdir("/usr", 0755) != 0) {
    perror("mkdir failed");
    return -1;
  }
  if (symlink("/bin", "/usr/bin") != 0 || symlink("/lib", "/usr/lib") != 0 ||
      symlink("/include", "/usr/include") != 0) {
    perror("symlink failed");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_usr_links>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     116b <create_usr_links+0x3b>
lea    0xeab(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <create_usr_links+0xb1>
lea    0xea4(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
jne    11c2 <create_usr_links+0x92>
lea    0xe90(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
jne    11c2 <create_usr_links+0x92>
lea    0xe7c(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
je     11da <create_usr_links+0xaa>
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <create_usr_links+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_usr_links>:
push   %rbx
lea    0xec8(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    119d <create_usr_links+0x6d>
lea    0xec8(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1040 <symlink@plt>
lea    0xed0(%rip),%rbx
test   %rax,%rax
jne    11a4 <create_usr_links+0x74>
lea    0xeb2(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1040 <symlink@plt>
test   %rax,%rax
jne    11a4 <create_usr_links+0x74>
lea    0xea3(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1040 <symlink@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a4 <create_usr_links+0x74>
pop    %rbx
ret
lea    0xe61(%rip),%rbx
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/usr\00"
@.str.1 = [13 x i8] c"mkdir failed\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@.str.4 = [5 x i8] c"/lib\00"
@.str.5 = [9 x i8] c"/usr/lib\00"
@.str.6 = [9 x i8] c"/include\00"
@.str.7 = [13 x i8] c"/usr/include\00"
@.str.8 = [15 x i8] c"symlink failed\00"
define i32 @create_usr_links() {
%1 = alloca i32
%2 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
6: ; preds = %0
%7 = call i64 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = call i64 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i64 @symlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12, %9, %6
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
17: ; preds = %12
store i32 0, i32* %1
br label %18
18: ; preds = %17, %15, %4
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"/usr\00"
@.str.1 = [13 x i8] c"mkdir failed\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [9 x i8] c"/usr/bin\00"
@.str.4 = [5 x i8] c"/lib\00"
@.str.5 = [9 x i8] c"/usr/lib\00"
@.str.6 = [9 x i8] c"/include\00"
@.str.7 = [13 x i8] c"/usr/include\00"
@.str.8 = [15 x i8] c"symlink failed\00"
define i32 @create_usr_links() {
%1 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i64 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i64 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i64 @symlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %3, %6, %9, %0
%13 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %9 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %3 ]
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ 0, %9 ], [ -1, %12 ]
ret i32 %16
}