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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
scalar_t__ dup(int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fflush(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
scalar_t__ lseek(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *tmpfile();
int main(int argc, char *argv[]) {
  FILE *x;
  int ch;
  if (lseek(0, 0, SEEK_SET) == 0) {
    execvp(argv[1], argv + 1);
    exit(111);
  }
  rewind(stdin);
  clearerr(stdin);
  x = tmpfile();
  if (!x)
    exit(111);
  while ((ch = fgetc(stdin)) != EOF)
    fputc(ch, x);
  if (ferror(stdin) || ferror(x) || fflush(x))
    exit(111);
  close(0);
  if (dup(fileno(x)) != 0)
    exit(111);
  if (fcntl(0, F_SETFD, 0) != 0)
    exit(111);
  if (lseek(0, 0, SEEK_SET) != 0)
    exit(111);
  execvp(argv[1], argv + 1);
  exit(111);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    %esi,%edi
call   1070 <lseek@plt>
cmp    $0x0,%rax
jne    1231 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10f0 <execvp@plt>
mov    $0x6f,%edi
call   1100 <exit@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%rdi
call   1050 <rewind@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%rdi
call   10c0 <clearerr@plt>
mov    $0x0,%al
call   10b0 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126f <main+0x8f>
mov    $0x6f,%edi
call   1100 <exit@plt>
jmp    1274 <main+0x94>
mov    0x2d6d(%rip),%rax
mov    (%rax),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d53(%rip),%rcx
cmp    (%rcx),%eax
je     12a6 <main+0xc6>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <fputc@plt>
jmp    1274 <main+0x94>
mov    0x2d3b(%rip),%rax
mov    (%rax),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    12e5 <main+0x105>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    12e5 <main+0x105>
mov    -0x18(%rbp),%rdi
call   10e0 <fflush@plt>
cmp    $0x0,%rax
je     12ef <main+0x10f>
mov    $0x6f,%edi
call   1100 <exit@plt>
xor    %edi,%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <dup@plt>
cmp    $0x0,%rax
je     131a <main+0x13a>
mov    $0x6f,%edi
call   1100 <exit@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1040 <fcntl@plt>
cmp    $0x0,%rax
je     1340 <main+0x160>
mov    $0x6f,%edi
call   1100 <exit@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    %esi,%edi
call   1070 <lseek@plt>
cmp    $0x0,%rax
je     1366 <main+0x186>
mov    $0x6f,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10f0 <execvp@plt>
mov    $0x6f,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    0x2dd5(%rip),%r15
mov    (%r15),%edx
xor    %edi,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
test   %rax,%rax
jne    1219 <main+0x39>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    %r14,%rsi
call   10f0 <execvp@plt>
jmp    12e8 <main+0x108>
mov    0x2dc8(%rip),%r12
mov    (%r12),%rdi
call   1050 <rewind@plt>
mov    (%r12),%rdi
call   10c0 <clearerr@plt>
xor    %eax,%eax
call   10b0 <tmpfile@plt>
test   %rax,%rax
je     12e8 <main+0x108>
mov    %rax,%rbx
mov    (%r12),%rdi
call   1080 <fgetc@plt>
mov    0x2d8b(%rip),%r13
cmp    0x0(%r13),%eax
je     1279 <main+0x99>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   10a0 <fputc@plt>
mov    (%r12),%rdi
call   1080 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    1260 <main+0x80>
mov    (%r12),%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12e8 <main+0x108>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12e8 <main+0x108>
mov    %rbx,%rdi
call   10e0 <fflush@plt>
test   %rax,%rax
jne    12e8 <main+0x108>
xor    %edi,%edi
call   1090 <close@plt>
mov    %rbx,%rdi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <dup@plt>
test   %rax,%rax
jne    12e8 <main+0x108>
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %rax,%rax
jne    12e8 <main+0x108>
mov    (%r15),%edx
xor    %edi,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
test   %rax,%rax
je     1204 <main+0x24>
mov    $0x6f,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stdin = global i32* null
@EOF = global i32 0
@F_SETFD = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @SEEK_SET
%9 = call i64 @lseek(i32 0, i32 0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = call i32 @execvp(i8* %14, i8** %16)
%18 = call i32 @exit(i32 111)
unreachable
19: ; preds = %2
%20 = load i32*, i32** @stdin
%21 = call i32 @rewind(i32* %20)
%22 = load i32*, i32** @stdin
%23 = call i32 @clearerr(i32* %22)
%24 = call i32* (...) @tmpfile()
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %29, label %27
27: ; preds = %19
%28 = call i32 @exit(i32 111)
unreachable
29: ; preds = %19
br label %30
30: ; preds = %35, %29
%31 = load i32*, i32** @stdin
%32 = call i32 @fgetc(i32* %31)
store i32 %32, i32* %7
%33 = load i32, i32* @EOF
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* %7
%37 = load i32*, i32** %6
%38 = call i32 @fputc(i32 %36, i32* %37)
br label %30
39: ; preds = %30
%40 = load i32*, i32** @stdin
%41 = call i64 @ferror(i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %51, label %43
43: ; preds = %39
%44 = load i32*, i32** %6
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = load i32*, i32** %6
%49 = call i64 @fflush(i32* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47, %43, %39
%52 = call i32 @exit(i32 111)
unreachable
53: ; preds = %47
%54 = call i32 @close(i32 0)
%55 = load i32*, i32** %6
%56 = call i32 @fileno(i32* %55)
%57 = call i64 @dup(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @exit(i32 111)
unreachable
61: ; preds = %53
%62 = load i32, i32* @F_SETFD
%63 = call i64 @fcntl(i32 0, i32 %62, i32 0)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @exit(i32 111)
unreachable
67: ; preds = %61
%68 = load i32, i32* @SEEK_SET
%69 = call i64 @lseek(i32 0, i32 0, i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @exit(i32 111)
unreachable
73: ; preds = %67
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = call i32 @execvp(i8* %76, i8** %78)
%80 = call i32 @exit(i32 111)
unreachable
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stdin = global i32* null
@EOF = global i32 0
@F_SETFD = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @SEEK_SET
%4 = tail call i64 @lseek(i32 0, i32 0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @execvp(i8* %8, i8** %7)
%10 = tail call i32 @exit(i32 111)
unreachable
11: ; preds = %2
%12 = load i32*, i32** @stdin
%13 = tail call i32 @rewind(i32* %12)
%14 = load i32*, i32** @stdin
%15 = tail call i32 @clearerr(i32* %14)
%16 = tail call i32* (...) @tmpfile()
%17 = icmp eq i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = load i32*, i32** @stdin
%20 = tail call i32 @fgetc(i32* %19)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %32, label %25
23: ; preds = %11
%24 = tail call i32 @exit(i32 111)
unreachable
25: ; preds = %18, %25
%26 = phi i32 [ %29, %25 ], [ %20, %18 ]
%27 = tail call i32 @fputc(i32 %26, i32* %16)
%28 = load i32*, i32** @stdin
%29 = tail call i32 @fgetc(i32* %28)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %25
32: ; preds = %25, %18
%33 = load i32*, i32** @stdin
%34 = tail call i64 @ferror(i32* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = tail call i64 @ferror(i32* %16)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = tail call i64 @fflush(i32* %16)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39, %36, %32
%43 = tail call i32 @exit(i32 111)
unreachable
44: ; preds = %39
%45 = tail call i32 @close(i32 0)
%46 = tail call i32 @fileno(i32* %16)
%47 = tail call i64 @dup(i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %44
%50 = tail call i32 @exit(i32 111)
unreachable
51: ; preds = %44
%52 = load i32, i32* @F_SETFD
%53 = tail call i64 @fcntl(i32 0, i32 %52, i32 0)
%54 = icmp eq i64 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %51
%56 = tail call i32 @exit(i32 111)
unreachable
57: ; preds = %51
%58 = load i32, i32* @SEEK_SET
%59 = tail call i64 @lseek(i32 0, i32 0, i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %57
%62 = tail call i32 @exit(i32 111)
unreachable
63: ; preds = %57
%64 = getelementptr inbounds i8*, i8** %1, i64 1
%65 = load i8*, i8** %64
%66 = tail call i32 @execvp(i8* %65, i8** %64)
%67 = tail call i32 @exit(i32 111)
unreachable
}