#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int quit(char *);
int system(char *);
int main() {
  char command[80];
  FILE *file = fopen("command.txt", "r");
  if (file == NULL) {
    return quit("Could not open "
                "command.txt"
                " for reading");
  }
  if (fgets(command, 80, file) == NULL) {
    return quit("Error when reading command from "
                "command.txt");
  }
  if (system(command) == -1) {
    return quit("Could not execute the command in "
                "command.txt");
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee3(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1195 <main+0x45>
lea    0xe7a(%rip),%rdi
call   1050 <quit@plt>
mov    %eax,-0x4(%rbp)
jmp    11fb <main+0xab>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11c5 <main+0x75>
lea    0xe71(%rip),%rdi
call   1050 <quit@plt>
mov    %eax,-0x4(%rbp)
jmp    11fb <main+0xab>
lea    -0x60(%rbp),%rdi
call   1040 <system@plt>
cmp    $0xffffffff,%eax
jne    11eb <main+0x9b>
lea    0xe77(%rip),%rdi
call   1050 <quit@plt>
mov    %eax,-0x4(%rbp)
jmp    11fb <main+0xab>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
lea    0xeed(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119e <main+0x4e>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11af <main+0x5f>
mov    %rsp,%rdi
call   1040 <system@plt>
cmp    $0xffffffff,%eax
je     11b8 <main+0x68>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11c4 <main+0x74>
lea    0xe5d(%rip),%rdi
add    $0x50,%rsp
pop    %rbx
jmp    1050 <quit@plt>
lea    0xe73(%rip),%rdi
jmp    11bf <main+0x6f>
lea    0xe96(%rip),%rdi
call   1050 <quit@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"command.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"Could not open command.txt for reading\00"
@.str.3 = [44 x i8] c"Error when reading command from command.txt\00"
@.str.4 = [45 x i8] c"Could not execute the command in command.txt\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 %8, i32* %1
br label %25
9: ; preds = %0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32* @fgets(i8* %10, i32 80, i32* %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @quit(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
store i32 %15, i32* %1
br label %25
16: ; preds = %9
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%18 = call i32 @system(i8* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @quit(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
store i32 %21, i32* %1
br label %25
22: ; preds = %16
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %1
br label %25
25: ; preds = %22, %20, %14, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [12 x i8] c"command.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"Could not open command.txt for reading\00"
@.str.3 = [44 x i8] c"Error when reading command from command.txt\00"
@.str.4 = [45 x i8] c"Could not execute the command in command.txt\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %19
7: ; preds = %0
%8 = call i32* @fgets(i8* %2, i32 80, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @quit(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %19
12: ; preds = %7
%13 = call i32 @system(i8* %2)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @quit(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %19
17: ; preds = %12
%18 = call i32 @fclose(i32* %3)
br label %19
19: ; preds = %17, %15, %10, %5
%20 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ 0, %17 ]
ret i32 %20
}