#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__ diff(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ replace_string(char **, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strdup(char *);
int /*<<< orphan*/ test_sem_fork();
int /*<<< orphan*/ test_sem_pthreads();
int /*<<< orphan*/ test_volumes();
scalar_t__ vrun(char *);
int main(int argc, char *argv[]) {
  if (diff("/etc/motd", "/etc/motd") != 0) {
    fprintf(stderr, "error on line %d\n", 251);
    exit(1);
  };
  if (diff("/etc/passwd", "/etc/motd") == 0) {
    fprintf(stderr, "error on line %d\n", 252);
    exit(1);
  };
  char *s = strdup("jolly old jolly old time...");
  char **sp = &s;
  if (strcmp(replace_string(sp, "old", "new"), "jolly new jolly new time...")) {
    fprintf(stderr, "error on line %d\n", 256);
    exit(1);
  };
  if (vrun("ls / /etc >/dev/null")) {
    fprintf(stderr, "error on line %d\n", 257);
    exit(1);
  };
  test_volumes();
  printf("all tests passed!\n");
  if (argc == 1)
    return 0;
  test_sem_fork();
  test_sem_pthreads();
  return 0;
}


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)
lea    0xe33(%rip),%rsi
mov    %rsi,%rdi
call   10d0 <diff@plt>
cmp    $0x0,%rax
je     1203 <main+0x53>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
mov    $0xfb,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe12(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10d0 <diff@plt>
cmp    $0x0,%rax
jne    1244 <main+0x94>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
mov    $0xfc,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xddd(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xddd(%rip),%rsi
lea    0xdda(%rip),%rdx
call   1050 <replace_string@plt>
mov    %eax,%edi
lea    0xdd0(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12af <main+0xff>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    $0x100,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdb2(%rip),%rdi
call   1070 <vrun@plt>
cmp    $0x0,%rax
je     12e9 <main+0x139>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    $0x101,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1030 <test_volumes@plt>
lea    0xd86(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1312 <main+0x162>
movl   $0x0,-0x4(%rbp)
jmp    1327 <main+0x177>
mov    $0x0,%al
call   1040 <test_sem_fork@plt>
mov    $0x0,%al
call   10a0 <test_sem_pthreads@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xe42(%rip),%rdi
mov    %rdi,%rsi
call   10d0 <diff@plt>
test   %rax,%rax
jne    1266 <main+0xb6>
lea    0xe46(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10d0 <diff@plt>
test   %rax,%rax
je     127d <main+0xcd>
lea    0xe36(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,0x8(%rsp)
lea    0xe41(%rip),%rsi
lea    0xe3e(%rip),%rdx
lea    0x8(%rsp),%rdi
call   1060 <replace_string@plt>
lea    0xe31(%rip),%rsi
mov    %eax,%edi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1294 <main+0xe4>
lea    0xe3a(%rip),%rdi
call   1070 <vrun@plt>
test   %rax,%rax
jne    12ab <main+0xfb>
xor    %eax,%eax
call   1040 <test_volumes@plt>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebx
je     125e <main+0xae>
xor    %eax,%eax
call   1050 <test_sem_fork@plt>
xor    %eax,%eax
call   10a0 <test_sem_pthreads@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
mov    $0xfb,%edx
jmp    12c0 <main+0x110>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
mov    $0xfc,%edx
jmp    12c0 <main+0x110>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
mov    $0x100,%edx
jmp    12c0 <main+0x110>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    $0x101,%edx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/etc/motd\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"error on line %d\0A\00"
@.str.2 = [12 x i8] c"/etc/passwd\00"
@.str.3 = [28 x i8] c"jolly old jolly old time...\00"
@.str.4 = [4 x i8] c"old\00"
@.str.5 = [4 x i8] c"new\00"
@.str.6 = [28 x i8] c"jolly new jolly new time...\00"
@.str.7 = [21 x i8] c"ls / /etc >/dev/null\00"
@.str.8 = [19 x i8] c"all tests passed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @diff(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 251)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i64 @diff(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 252)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = call i8* @strdup(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i8* %22, i8** %6
store i8** %6, i8*** %7
%23 = load i8**, i8*** %7
%24 = call i32 @replace_string(i8** %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%25 = call i64 @strcmp(i32 %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 256)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = call i64 @vrun(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 257)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i32 (...) @test_volumes()
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 0, i32* %3
br label %47
44: ; preds = %38
%45 = call i32 (...) @test_sem_fork()
%46 = call i32 (...) @test_sem_pthreads()
store i32 0, i32* %3
br label %47
47: ; preds = %44, %43
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [10 x i8] c"/etc/motd\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"error on line %d\0A\00"
@.str.2 = [12 x i8] c"/etc/passwd\00"
@.str.3 = [28 x i8] c"jolly old jolly old time...\00"
@.str.4 = [4 x i8] c"old\00"
@.str.5 = [4 x i8] c"new\00"
@.str.6 = [28 x i8] c"jolly new jolly new time...\00"
@.str.7 = [21 x i8] c"ls / /etc >/dev/null\00"
@str = [18 x i8] c"all tests passed!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = tail call i64 @diff(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 251)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i64 @diff(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 252)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = bitcast i8** %3 to i8*
%19 = tail call dereferenceable_or_null(28) i8* @strdup(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %3
%20 = call i32 @replace_string(i8** %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%21 = call i64 @strcmp(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 256)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = call i64 @vrun(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 257)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = call i32 (...) @test_volumes()
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%37 = icmp eq i32 %0, 1
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = call i32 (...) @test_sem_fork()
%40 = call i32 (...) @test_sem_pthreads()
br label %41
41: ; preds = %34, %38
ret i32 0
}