#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;
};
typedef int /*<<< orphan*/ path;

/* Variables and functions */
char *get_app_path();
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ symlink(char *, char *);
void gallery_init(void) {
  char path[256];
  struct stat buf;
  snprintf(path, sizeof(path), "%s/web_root/DCIM", get_app_path());
  if (lstat(path, &buf) != 0) {
    symlink("/sdcard/DCIM", path);
  }
}


x86 assembly (clang, -O0):
<gallery_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    $0x0,%al
call   1060 <get_app_path@plt>
mov    -0x110(%rbp),%rdi
mov    %rax,%rcx
mov    $0x100,%esi
lea    0xe8a(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x100(%rbp),%rdi
lea    -0x108(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
je     11ab <gallery_init+0x6b>
lea    -0x100(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1030 <symlink@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gallery_init>:
push   %rbx
sub    $0x110,%rsp
xor    %eax,%eax
call   1060 <get_app_path@plt>
lea    0xeaa(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <lstat@plt>
test   %rax,%rax
je     118e <gallery_init+0x4e>
lea    0xe8d(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1030 <symlink@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"%s/web_root/DCIM\00"
@.str.1 = [13 x i8] c"/sdcard/DCIM\00"
define void @gallery_init() {
%1 = alloca [256 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i8* (...) @get_app_path()
%5 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = call i64 @lstat(i8* %6, %struct.stat* %2)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = call i32 @symlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %0
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"%s/web_root/DCIM\00"
@.str.1 = [13 x i8] c"/sdcard/DCIM\00"
define void @gallery_init() {
%1 = alloca [256 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = tail call i8* (...) @get_app_path()
%6 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i64 @lstat(i8* %3, %struct.stat* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @symlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %11
11: ; preds = %9, %0
ret void
}