#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*/ str;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
size_t strcspn(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc <= 1)
    return 1;
  FILE *mf;
  char str[1024], firstStr[512], secondStr[512];
  char *estr;
  mf = fopen("/var/lib/asterisk/documentation/text.txt", "r");
  if (mf == NULL)
    return -1;
  while (1) {
    estr = fgets(str, sizeof(str), mf);
    if (estr == NULL)
      break;
    strcpy(firstStr, strtok(str, ";"));
    strcpy(secondStr, strtok(NULL, ";"));
    secondStr[strcspn(secondStr, "\n")] = 0;
    if (strcmp(secondStr, argv[1]) == 0) {
      printf("SET VARIABLE calleridvar \"%s\"\n", firstStr);
      fclose(mf);
      return 0;
    }
  }
  printf("SET VARIABLE calleridvar \"%s\"\n", argv[1]);
  fclose(mf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11af <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    12f6 <main+0x176>
lea    0xe4a(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dd <main+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <main+0x176>
jmp    11e2 <main+0x62>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    1211 <main+0x91>
jmp    12d2 <main+0x152>
lea    -0x620(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x838(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd2(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x830(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x820(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1060 <strcspn@plt>
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12cd <main+0x14d>
lea    -0x620(%rbp),%rsi
lea    0xd7a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x176>
jmp    11e2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd4c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1286 <main+0x106>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
lea    0xe57(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1254 <main+0xd4>
mov    %rax,%r15
lea    0x400(%rsp),%r12
lea    0xe5b(%rip),%rbx
mov    %rsp,%rbp
lea    0xe70(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125b <main+0xdb>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
lea    0x200(%rsp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%rsp,%rax,1)
mov    0x8(%r14),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11e0 <main+0x60>
lea    0xde3(%rip),%rdi
lea    0x200(%rsp),%rsi
jmp    1266 <main+0xe6>
mov    $0xffffffff,%eax
jmp    1275 <main+0xf5>
mov    0x8(%r14),%rsi
lea    0xdc7(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/var/lib/asterisk/documentation/text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c";\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [31 x i8] c"SET VARIABLE calleridvar \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %57
14: ; preds = %2
%15 = call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %3
br label %57
19: ; preds = %14
br label %20
20: ; preds = %19, %49
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i8* @fgets(i8* %21, i32 1024, i32* %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %20
br label %50
27: ; preds = %20
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i32 @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @strcpy(i8* %28, i32 %30)
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%33 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @strcpy(i8* %32, i32 %33)
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%36 = call i64 @strcspn(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %38, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %27
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %3
br label %57
49: ; preds = %27
br label %20
50: ; preds = %26
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %3
br label %57
57: ; preds = %50, %44, %18, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [41 x i8] c"/var/lib/asterisk/documentation/text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c";\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [31 x i8] c"SET VARIABLE calleridvar \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = icmp slt i32 %0, 2
br i1 %6, label %37, label %7
7: ; preds = %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %35, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 1
br label %15
15: ; preds = %13, %18
%16 = call i8* @fgets(i8* %8, i32 1024, i32* %11)
%17 = icmp eq i8* %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = call i32 @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcpy(i8* %9, i32 %19)
%21 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @strcpy(i8* %10, i32 %21)
%23 = call i64 @strcspn(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %14
%26 = call i64 @strcmp(i8* %10, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %18
%29 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %33
30: ; preds = %15
%31 = load i8*, i8** %14
%32 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %30
%34 = call i32 @fclose(i32* %11)
br label %35
35: ; preds = %33, %7
%36 = phi i32 [ -1, %7 ], [ 0, %33 ]
br label %37
37: ; preds = %2, %35
%38 = phi i32 [ %36, %35 ], [ 1, %2 ]
ret i32 %38
}