#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*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ test1(char *, size_t, char *);
int /*<<< orphan*/ test2(char *, size_t, char *);
int main(int argc, char **argv) {
  size_t to_size = 100;
  char *to = (char *)malloc(to_size);
  size_t from_size = 20;
  char *from = (char *)malloc(from_size);
  memset(from, 'z', from_size);
  from[from_size - 1] = '\0';
  if (argc != 2)
    return 1;
  if (!strcmp(argv[1], "test1"))
    test1(to, to_size, from);
  if (!strcmp(argv[1], "test2"))
    test2(to, to_size, from);
  free(to);
  free(from);
  return 0;
}


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)
movq   $0x64,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x14,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x7a,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x2,-0x8(%rbp)
je     11d8 <main+0x78>
movl   $0x1,-0x4(%rbp)
jmp    124d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe19(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1206 <main+0xa6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <test1@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1234 <main+0xd4>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <test2@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%edx
mov    %rax,%rdi
mov    $0x7a,%esi
call   1050 <memset@plt>
movb   $0x0,0x13(%rbx)
mov    $0x1,%eax
cmp    $0x2,%ebp
jne    1207 <main+0xa7>
mov    0x8(%r15),%r12
lea    0xe4e(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11d2 <main+0x72>
mov    $0x64,%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <test1@plt>
mov    0x8(%r15),%r12
lea    0xe2d(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11f5 <main+0x95>
mov    $0x64,%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1080 <test2@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test1\00"
@.str.1 = [6 x i8] c"test2\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 100, i64* %6
%10 = load i64, i64* %6
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
store i64 20, i64* %8
%13 = load i64, i64* %8
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = load i64, i64* %8
%18 = call i32 @memset(i8* %16, i8 signext 122, i64 %17)
%19 = load i8*, i8** %9
%20 = load i64, i64* %8
%21 = sub i64 %20, 1
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 1, i32* %3
br label %53
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %26
%33 = load i8*, i8** %7
%34 = load i64, i64* %6
%35 = load i8*, i8** %9
%36 = call i32 @test1(i8* %33, i64 %34, i8* %35)
br label %37
37: ; preds = %32, %26
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %37
%44 = load i8*, i8** %7
%45 = load i64, i64* %6
%46 = load i8*, i8** %9
%47 = call i32 @test2(i8* %44, i64 %45, i8* %46)
br label %48
48: ; preds = %43, %37
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %9
%52 = call i32 @free(i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %48, %25
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [6 x i8] c"test1\00"
@.str.1 = [6 x i8] c"test2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @malloc(i64 100)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i64 20)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i8 signext 122, i64 20)
%8 = getelementptr inbounds i8, i8* %6, i64 19
store i8 0, i8* %8
%9 = icmp eq i32 %0, 2
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @test1(i8* %4, i64 100, i8* %6)
%17 = load i8*, i8** %11
br label %18
18: ; preds = %15, %10
%19 = phi i8* [ %17, %15 ], [ %12, %10 ]
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @test2(i8* %4, i64 100, i8* %6)
br label %24
24: ; preds = %22, %18
%25 = tail call i32 @free(i8* %4)
%26 = tail call i32 @free(i8* %6)
br label %27
27: ; preds = %2, %24
%28 = phi i32 [ 0, %24 ], [ 1, %2 ]
ret i32 %28
}