#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*/ _test_sysio_shutdown();
int errno;
int /*<<< orphan*/ exit(int);
int getopt(int, char *const *, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int rename(char const *, char const *);
int /*<<< orphan*/ umask(int);
int /*<<< orphan*/ usage();
int main(int argc, char *const argv[]) {
  int i;
  int err;
  const char *spath, *dpath;
  extern int _test_sysio_startup(void);
  while ((i = getopt(argc, argv, "")) != -1)
    switch (i) {
    default:
      usage();
    }
  if (!(argc - optind))
    usage();
  err = _test_sysio_startup();
  if (err) {
    errno = -err;
    perror("sysio startup");
    exit(1);
  }
  (void)umask(022);
  spath = argv[optind++];
  if (!(argc - optind))
    usage();
  dpath = argv[optind++];
  if (argc - optind)
    usage();
  err = rename(spath, dpath);
  if (err)
    perror("rename");
  _test_sysio_shutdown();
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11c1 <main+0x41>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    1196 <main+0x16>
mov    -0x8(%rbp),%eax
mov    0x2e1d(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jne    11dd <main+0x5d>
mov    $0x0,%al
call   1050 <usage@plt>
call   1060 <_test_sysio_startup@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1213 <main+0x93>
xor    %ecx,%ecx
sub    -0x18(%rbp),%ecx
mov    0x2ddd(%rip),%rax
mov    %ecx,(%rax)
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x12,%edi
call   1040 <umask@plt>
mov    -0x10(%rbp),%rax
mov    0x2dc0(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2db2(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d9b(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jne    125f <main+0xdf>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d7e(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d70(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d59(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
je     12a1 <main+0x121>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <rename@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12c7 <main+0x147>
lea    0xd4c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <_test_sysio_shutdown@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe81(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x49>
lea    0xe70(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <usage@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
mov    0x2e18(%rip),%rbx
cmp    %ebp,(%rbx)
jne    11db <main+0x5b>
xor    %eax,%eax
call   1050 <usage@plt>
call   1060 <_test_sysio_startup@plt>
test   %eax,%eax
jne    1250 <main+0xd0>
mov    $0x12,%edi
call   1040 <umask@plt>
movslq (%rbx),%rcx
lea    0x1(%rcx),%eax
mov    %eax,(%rbx)
mov    (%r14,%rcx,8),%r15
cmp    %ebp,%eax
jne    1207 <main+0x87>
xor    %eax,%eax
call   1050 <usage@plt>
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
cltq
mov    (%r14,%rax,8),%rbx
cmp    %ebp,%ecx
je     121d <main+0x9d>
xor    %eax,%eax
call   1050 <usage@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <rename@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1242 <main+0xc2>
xor    %eax,%eax
call   1030 <_test_sysio_shutdown@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc5(%rip),%rdi
call   1070 <perror@plt>
jmp    122e <main+0xae>
neg    %eax
mov    0x2d7f(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd9e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@.str.2 = [7 x i8] c"rename\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %17 [
]
17: ; preds = %15
%18 = call i32 (...) @usage()
br label %19
19: ; preds = %17
br label %10
20: ; preds = %10
%21 = load i32, i32* %4
%22 = load i32, i32* @optind
%23 = sub nsw i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %25, %20
%28 = call i32 @_test_sysio_startup()
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sub nsw i32 0, %32
store i32 %33, i32* @errno
%34 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = call i32 @umask(i32 18)
%38 = load i8**, i8*** %5
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
store i32 %40, i32* @optind
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8*, i8** %38, i64 %41
%43 = load i8*, i8** %42
store i8* %43, i8** %8
%44 = load i32, i32* %4
%45 = load i32, i32* @optind
%46 = sub nsw i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %36
%49 = call i32 (...) @usage()
br label %50
50: ; preds = %48, %36
%51 = load i8**, i8*** %5
%52 = load i32, i32* @optind
%53 = add nsw i32 %52, 1
store i32 %53, i32* @optind
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8*, i8** %51, i64 %54
%56 = load i8*, i8** %55
store i8* %56, i8** %9
%57 = load i32, i32* %4
%58 = load i32, i32* @optind
%59 = sub nsw i32 %57, %58
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %50
%62 = call i32 (...) @usage()
br label %63
63: ; preds = %61, %50
%64 = load i8*, i8** %8
%65 = load i8*, i8** %9
%66 = call i32 @rename(i8* %64, i8* %65)
store i32 %66, i32* %7
%67 = load i32, i32* %7
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %71
71: ; preds = %69, %63
%72 = call i32 (...) @_test_sysio_shutdown()
%73 = load i32, i32* %7
ret i32 %73
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@.str.2 = [7 x i8] c"rename\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @usage()
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %5
9: ; preds = %5, %2
%10 = load i32, i32* @optind
%11 = icmp eq i32 %10, %0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (...) @usage()
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @_test_sysio_startup()
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = sub nsw i32 0, %15
store i32 %18, i32* @errno
%19 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = tail call i32 @umask(i32 18)
%23 = load i32, i32* @optind
%24 = add nsw i32 %23, 1
store i32 %24, i32* @optind
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = icmp eq i32 %24, %0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = tail call i32 (...) @usage()
%31 = load i32, i32* @optind
br label %32
32: ; preds = %29, %21
%33 = phi i32 [ %31, %29 ], [ %24, %21 ]
%34 = add nsw i32 %33, 1
store i32 %34, i32* @optind
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = icmp eq i32 %34, %0
br i1 %38, label %41, label %39
39: ; preds = %32
%40 = tail call i32 (...) @usage()
br label %41
41: ; preds = %39, %32
%42 = tail call i32 @rename(i8* %27, i8* %37)
%43 = icmp eq i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = tail call i32 (...) @_test_sysio_shutdown()
ret i32 %42
}