#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
char *strtok(char *, char *);
int confirm_program(char *path, char *prog) {
  char fname[2 * 1024 + 1];
  char *fptr;
  struct stat buf;
  int rval;
  sprintf(fname, "%s/%s", path, prog);
  fptr = strtok(fname, " ");
  rval = stat(fptr, &buf);
  return (rval == 0);
}


x86 assembly (clang, -O0):
<confirm_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xea7(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x820(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0x0,-0x834(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<confirm_program>:
push   %rbx
sub    $0x820,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xebb(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <stat@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x820,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c" \00"
define i32 @confirm_program(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2049 x i8]
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [2049 x i8], [2049 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = getelementptr inbounds [2049 x i8], [2049 x i8]* %5, i64 0, i64 0
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = call i32 @stat(i8* %15, %struct.stat* %7)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c" \00"
define i32 @confirm_program(i8* %0, i8* %1) {
%3 = alloca [2049 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @stat(i8* %8, %struct.stat* %4)
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
ret i32 %11
}